UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 1st March 2010, 08:16 PM   #1 (permalink)
shopserver
Registered User
 
Join Date: May 2004
Posts: 9
MySQL access

I amtrying to access MySQL and get the folowing error message from PHP, even though it seems to be able to access the data. Can anyone advise what is wrong with my script. The following error is displayed by php:
"An error occurred in script '/var/www/html/contacts_addresses-show.php' on line 47:
Use of undefined constant firstname - assumed 'firstname'
Date/Time: 3-1-2010 21:02:54"
The errors seems to be with the selected variables firstname and
lastname. However, these fields are defined in my
"xxxxxxxxxxx_co_uk_-_xxxxxxxxxx" database master_name table. What is wrong with the script (see line 47 below?


<?php
// Set the variables for the database access:
$Host = "127.0.0.1";
$User = "john";
$Password = "xxxxxxxxxxxx";
$DBName = "xxxxxxxxxxx_co_uk_-_xxxxxxxxxx";
$TableName = "master_name";

$Link = mysql_connect ($Host, $User, $Password);
print ("<INPUT TYPE=HIDDEN
NAME=\"an_address\"
VALUE=\"$an_address\">\n");
print ("an_address is $an_address");

print("<B>This simple script shows the family member with name_id=2</B><BR><BR>\n");
$query_names =
"SELECT firstname, lastname
FROM master_name
WHERE name_id = '2' "
;

$family_members_names = mysql_db_query ($DBName, $query_names, $Link);

// Create a table.
print ("<TABLE BORDER=1 WIDTH=\"90%\" CELLSPACING=1 CELLPADDING=1 ALIGN=LEFT \n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
printf ("<TD ALIGN=CENTER VALIGN=TOP >First Name</TD>\n");
printf ("<TD ALIGN=CENTER VALIGN=TOP >Last Name</TD>\n");
print ("</TR>\n");

$address_number = 0;
// fetch the results from the database, row by row.
while ($family_member = mysql_fetch_array ($family_members_names)) {
$address_number = $address_number + 1;
$family_member_first_name = $family_member[firstname]; // this line causes an error "Use of undefined constant firstname - assumed 'firstname'" - have asked United Hosting to assist 20100227sat

I appreciate you help.

John
shopserver is offline   Reply With Quote
Old 2nd March 2010, 06:01 AM   #2 (permalink)
Tim
Bloke
 
Join Date: Nov 2005
Location: Halifax UK
Posts: 638
Try sticking quotes around your constant like this:

$family_member_first_name = $family_member['firstname'];
Tim is offline   Reply With Quote
Old 2nd March 2010, 10:36 AM   #3 (permalink)
slater
Registered User
 
Join Date: Mar 2010
Posts: 3
Is there a closing "}" curly bracket missing from the while statement?
slater is offline   Reply With Quote
Old 2nd March 2010, 08:33 PM   #4 (permalink)
shopserver
Registered User
 
Join Date: May 2004
Posts: 9
MySQL access

Tim

Thanks a Million - your suggestion worked. I spent a long time trying to resolve this problem. In the end I contacted United Hosting and Matt (UH Support) suggested I try this forum. Your response was practically immediate!

Again, than you for replying so quickly. Hopefully, with my increasing competence, I'll be able to also assist in our ever expanding PHP technical community.

[slater, thank you for also replying]

John (shopserver)
shopserver is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 06:43 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  SEO by vBSEO 3.0.0
Copyright © 1998-2009 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309