Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » mysql_query(): supplied argument is not a valid MySQL-Link resource in...
Closed Thread
Old 05-07-2007, 04:25 PM   #1 (permalink)
 
True Techie

Join Date: Feb 2006

Posts: 228

selina

Send a message via ICQ to selina Send a message via Yahoo to selina
Default mysql_query(): supplied argument is not a valid MySQL-Link resource in...

i have a problem for PHP4, maybe you can help me.
i'm getting the error message:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in //path/rsvp.php on line 9

for the code:
<?php
$mysql = mysql_connect("localhost", "userid", "pw", "databse");
/* check connection */
if (!$mysql) {
die ('could not connect: ' . mysql_error());
}
else {
$display_block="name to find is \"" .$_POST["name"]."\"<br />";
$namesearch_sql="SELECT * FROM tbl_guests WHERE guest_name LIKE '".$_POST['name']."%'";
$namesearch_res=mysql_query($mysql, $namesearch_sql) or die(mysql_error($mysql));
if (mysql_num_rows($namesearch_res) < 1) {
$display_block .= "no name";
}
else {
$display_block="name found.";
}
/* close connection */
mysql_close($mysql);
}
?>
selina is offline  
Old 05-10-2007, 01:41 AM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: mysql_query(): supplied argument is not a valid MySQL-Link resource in...

Code:
<?php

$mysql = mysql_connect ('localhost','userid','pw','database');
if (!$mysql) {
	die ('Could not connect: '.mysql_error().'');
} else {
	
	$display_block = 'Name to find is '.$_POST['name'].'<br />';
	$namesearch_sql = 'SELECT * FROM tbl_guests WHERE guest_name LIKE '{$_POST['name']}'';
		if ($namesearch_res = mysql_query ($namesearch_sql)) { // Run the query
			if (mysql_num_rows ($namesearch_res) < 1) {
				$display_block .= "no name";
			} else {
				$display_block = "name found.";
			}
			
		} else { // Query didn't run
			die ('<p>Error: '.mysql_error().'</p>');
		}

mysql_close();

?>
I re-wrote it for you, a little neater. See if it works.
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On