Jump to content

db table not opening


Kayz

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225508
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225535
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225649
Share on other sites

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
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-225658
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/46335-db-table-not-opening/#findComment-226216
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.