freejellyfish Posted July 27, 2008 Share Posted July 27, 2008 Hi, i would like to look up whether a name is allready in the database or not. I copied the following code directly from my book (Codin for the Web): $data = mysql_query('SELECT \'id\' FROM members WHERE name = \'$name\'', $mysql_connection) [color=red]<== line 4[/color] or die("Could NOT select data from members due to ".mysql_error()); $found = @mysql_result($data, 0, 0); But if the name is not in the database i get this: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /data/apache/users/kilu.de/www/project/login_functions.php on line 4 Could NOT select data from members due to What is my n00bish mistake this time? I am happy about any help greez -jellyfish Quote Link to comment https://forums.phpfreaks.com/topic/116842-solved-how-to-check-an-entry-in-mysql/ Share on other sites More sharing options...
Nhoj Posted July 27, 2008 Share Posted July 27, 2008 Try something like the following: $data = mysql_query('SELECT count(0) FROM `members` WHERE `name` = "'.$name.'"', $mysql_connection); $found = mysql_result($data, 0); Quote Link to comment https://forums.phpfreaks.com/topic/116842-solved-how-to-check-an-entry-in-mysql/#findComment-600816 Share on other sites More sharing options...
.josh Posted July 27, 2008 Share Posted July 27, 2008 While you do have a problem with your query string (due to not using quotes properly), that is not what is causing the problem. The problem is that you are not successfully connecting to the database. Where is $mysql_connection being set? $mysql_connection should look like this: $mysql_connection = mysql_connect('localhost','dbusername','dbpassword'); // have to change the arguments to your info and then you need to select the database with $db = mysql_select_db('dbname',$mysql_connection); // have to change dbname to your database name Quote Link to comment https://forums.phpfreaks.com/topic/116842-solved-how-to-check-an-entry-in-mysql/#findComment-600852 Share on other sites More sharing options...
freejellyfish Posted July 27, 2008 Author Share Posted July 27, 2008 thanks! it was a typing mistake it is $mysql_id not $mysql_connection .... Quote Link to comment https://forums.phpfreaks.com/topic/116842-solved-how-to-check-an-entry-in-mysql/#findComment-601001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.