Jump to content

[SOLVED] How to check an entry in mysql?


freejellyfish

Recommended Posts

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? :D

I am happy about any help ;)

 

greez

 

-jellyfish

Link to comment
https://forums.phpfreaks.com/topic/116842-solved-how-to-check-an-entry-in-mysql/
Share on other sites

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

 

 

Archived

This topic is now archived and is closed to further replies.

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