Re: how to use PHP variable in MYSQL query?
Posted by:
Thomas Rye
Date: January 22, 2008 05:51PM
I was having the same problem and this did not fix it.
I am building a simple user database for my site.
I have the user addition PHP working, but I have an activation page (to confirm real emails)
From the activation page:
$username = $_POST['username'];
//... Database Connects, etc etc, then lower...
$result =
mysql_query("SELECT * FROM `tbl-user` WHERE `username` = '" . $username ."'") or die ("Error: " . mysql_error());
if (mysql_num_rows($result)<1) {
//Returns to Form with "Username not found" error note
} else {
//Goes on with activating account
I too have tried many different ways of implementing the $username and it won't work.
But when I just put in a username from the database hard-coded, it works.
PS - All the quotes around $username up there is single-quote ('), double-quotes ("), .$username., double-quotes("), single-quote('), double-quotes(")