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.
select from db using a variable
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: select from db using a variable
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
}(#10850)