Kayz Posted April 9, 2007 Share Posted April 9, 2007 Im trying to call information from a database, the following code is inside a secure place when the members log in they should be able to see their own user details: <?php $hostname = "***********"; $username = "***********"; $password = "****"; if(!($link = mysql_connect("****", "****","****"))) die("Could not connect to database."); $databasename = "mdb_am663"; if(!(mysql_select_db($databasename,$link))) die("Could not open table."); $member_id = $HTTP_GET_VARS['id']; $strsql="SELECT email, firstname, surname, address_line1, ". "address_line2, city_county, postcode FROM ". "contacts WHERE id = '$member_id'"; if(!($rs= mysql_query($strsql, $link))) die("Could not open table."); <<<<<<<<<<<<<<--------------------------------- //only one row should be returned $row = @ mysql_fetch_array($rs); // now complete the form echo "t<input type=\"hidden\" name=\"email\" value=\"$row[email]\"><br>\n"; echo "<input type=\"hidden\" name=\"first_name\" value=\"$row[firstname]\"><br>\n"; echo "<input type=\"hidden\" name=\"last_name\" value=\"$row[surname]\"><br>\n"; echo "<input type=\"hidden\" name=\"address1\" value = \"$row[address_line1]\"><br>\n"; echo "<input type=\"hidden\" name=\"address2\" value = \"$row[address_line2]\"><br>\n"; echo "<input type=\"hidden\" name=\"city\" value=\"$row[city_county]\"><br>\n"; echo "<input type=\"hidden\" name=\"state\" value=\"$row[postcode]\"><br>\n"; ?> where i have indicated with a "<<<<<<<<<<<<<<---------------------------------" this is where it sql ends for some reason telling me: Could not open table. anybody have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/ Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 Replace line die("Could not open table."); //with die(mysql_error()); and see error you get Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225437 Share on other sites More sharing options...
btherl Posted April 10, 2007 Share Posted April 10, 2007 Better still, use die("Error in $strsql\n" . mysql_error()); That will show you the query you tried to run (which very likely has a syntax error or a mistyped column name). Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225505 Share on other sites More sharing options...
Kayz Posted April 10, 2007 Author Share Posted April 10, 2007 good stuff, it now says: "Unknown column 'id' in 'where clause'" i changed the id's to "member_id" and it shows me a blank page? Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225507 Share on other sites More sharing options...
Kayz Posted April 10, 2007 Author Share Posted April 10, 2007 Better still, use die("Error in $strsql\n" . mysql_error()); That will show you the query you tried to run (which very likely has a syntax error or a mistyped column name). yes my friend that was a good one it said: Error in SELECT email, firstname, surname, address_line1, address_line2, city_county, postcode FROM contacts WHERE id = '' Unknown column 'id' in 'where clause' even ive changed the id into member_id it gave me white page. blank Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225508 Share on other sites More sharing options...
btherl Posted April 10, 2007 Share Posted April 10, 2007 Can you post your new code, where you changed id to member_id? A blank page often indicates a syntax error in your php code (rather than an error in the mysql query). If you are able to, edit php.ini and set display_errors to on. Also, it's safe to write like this: echo "t<input type=\"hidden\" name=\"email\" value=\"{$row['email']}\"><br>\n"; instead of this echo "t<input type=\"hidden\" name=\"email\" value=\"$row[email]\"><br>\n"; The {} protects the variable from being misread, and the single quotes around email protect it from being misinterpreted as a defined value. Your code will usually work without those, but occasionally it may not. Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225535 Share on other sites More sharing options...
Kayz Posted April 10, 2007 Author Share Posted April 10, 2007 <?php $hostname = "*****"; $username = "*****"; $password = "*****"; if(!($link = mysql_connect("*****", "*****","*****"))) die("Could not connect to database."); $databasename = "*****"; if(!(mysql_select_db($databasename,$link))) die("Could not open table."); $member_id = $HTTP_GET_VARS['id']; <<<<<<<----------------------- $strsql="SELECT email, firstname, surname, address_line1, ". "address_line2, city_county, postcode FROM ". "contacts WHERE id = '$member_id'"; <<<<<<<----------------------- if(!($rs= mysql_query($strsql, $link))) die("Error in $strsql\n" . mysql_error()); //only one row should be returned $row = @ mysql_fetch_array($rs); // now complete the form echo "t<input type=\"hidden\" name=\"email\" value=\"{$row['email']}\"><br>\n"; ?> I have indidcated the "id's" with <<<<<<<----------------------- which gives me this error: Error in SELECT email, firstname, surname, address_line1, address_line2, city_county, postcode FROM contacts WHERE id = '' Unknown column 'id' in 'where clause' But if i change it to member_id then i get a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225649 Share on other sites More sharing options...
esukf Posted April 10, 2007 Share Posted April 10, 2007 Check the contact table in your database. You don't have a column named 'id'. Is the column named 'member_id'?? If so, change you query to:- <?php $strsql="SELECT email, firstname, surname, address_line1, ". "address_line2, city_county, postcode FROM ". "contacts WHERE member_id = '$id'"; //member_id is the name of the column, $id is the value from $_GET ?> Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225658 Share on other sites More sharing options...
Kayz Posted April 10, 2007 Author Share Posted April 10, 2007 Check the contact table in your database. You don't have a column named 'id'. Is the column named 'member_id'?? If so, change you query to:- <?php $strsql="SELECT email, firstname, surname, address_line1, ". "address_line2, city_county, postcode FROM ". "contacts WHERE member_id = '$id'"; //member_id is the name of the column, $id is the value from $_GET ?> same problem its blank page Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-226216 Share on other sites More sharing options...
calabiyau Posted April 10, 2007 Share Posted April 10, 2007 There is more to your code right? Perhaps you should post the whole code, cuz what you have included doesn't display anything...it's just a bunch of hidden input fields. Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-226242 Share on other sites More sharing options...
Kayz Posted April 10, 2007 Author Share Posted April 10, 2007 There is more to your code right? Perhaps you should post the whole code, cuz what you have included doesn't display anything...it's just a bunch of hidden input fields. the rest of it is on tiop ^^ Quote Link to comment https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-226358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.