Jump to content

[SOLVED] I don't understand what's wrong with this query!!!


Recommended Posts

Thanks in advance for any help! I have this little query to look for any records that ALREADY use the entered screen name. Here's my query (built in php):

$name_sql = "SELECT member.screen_name,
		      member.public_email
          FROM	member
	  WHERE  member.screen_name = ".$screen_name;


//mysql_query returns true for success or false for error
$result = mysql_query($name_sql,dbconnect()) or die(mysql_error($mysql));

 

If the user had entered "weemikey" as a screen name, for example, the error I would get is 'Unknown column 'weemikey' in 'where clause'. So I take it mysql thinks the value of my variable $screen_name is a column in the database? I am using all kinds of queries that look just like this and I do NOT understand why it's doing this. Any ideas that are so obvious I would have walked right by?

$name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE  member.screen_name = '$screen_name'";

 

I think that should work ;)

 

$name_sql = "SELECT member.screen_name, member.public_email FROM member WHERE  member.screen_name = '" . $screen_name . "'";

 

Try that if the first doesn't. I think they should both work though.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.