MySQL Forums
Forum List  »  PHP

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(")

Options: ReplyQuote


Subject
Written By
Posted
Re: how to use PHP variable in MYSQL query?
January 22, 2008 05:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.