Jump to content

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

 

 

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.