Page 1 of 1

select from db using a variable

Posted: Sat Mar 13, 2010 7:35 pm
by phphlp47
Is it possible to do a select from a db table using a variable in the WHERE clause?

I have coded this but it does not return the field values in the php part of the form;

$rs_settings = mysql_query("select * from users WHERE id=@'saved_id'") or die(mysql_error());

I'm executing it with mypage.php?saved_id=2 ,
when I get this working I will be executing this from a page where the admin user will select the user then be presented
with just that users record.

I get the page displaying 2 in the record id but none of the other fields for id=2, I'm assuming its not actually reading the db.

Can somebody please advise the correct format to achieve this.

Re: select from db using a variable

Posted: Sat Mar 13, 2010 11:28 pm
by Christopher
Do this:

Code: Select all

$saved_id = mysql_real_escape_string($_GET['saved_id'],  $link);
$rs_settings = mysql_query("select * from users WHERE id='$saved_id'",  $link);
if (!mysql_error($link)) {
     // display results
} else {
     // display error message
}