Invalid mysql_query argument.
Posted: Thu Feb 17, 2005 8:09 am
hey,
I got a php script where users can fill in a name in a textbox and the script will search if there are any matches in the database.
I use the following function to connect to the database:
later on in the script, i use this to save the results of a query to $sql.
And later on i close the connection with:
There's also a function which writes the html search form to the page.
I get an error after i submitted that form.
Error:
$sql = mysql_query($query, $conn);
However when i replace this line with:
$sql = mysql_query($query, dbConn());
it gives no problems. when i write both the $link value and the $conn value to the page it both says somethign like: id resource #2.
Can someone tell me why i get this error? and how to solve it?
thx in advance.
I got a php script where users can fill in a name in a textbox and the script will search if there are any matches in the database.
I use the following function to connect to the database:
Code: Select all
<?php
function dbConn(){
$server = "localhost";
$user = "web37";
$password = "******";
$database = "usr_web37_1";
$link = mysql_connect($server, $user, $password) or die(mysql_error());
if(!@mysql_select_db($database, $link)){
echo "ERROR: <br /><br />";
echo mysql_error();
}
return $link;
}
$conn = dbConn();Code: Select all
$userSearchReq = " WHERE (Username = '{$_POSTї'searchUser']}')";
$query = "SELECT * FROM user_info" . $userSearchReq;
$sql = mysql_query($query, $conn);
if(!$sql){
echo "Error: <br />";
echo mysql_error();
exit();
}
// ____Here comes the code for writing all matches to a table. _____Code: Select all
mysql_close($conn);I get an error after i submitted that form.
Error:
63 is this line:Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/web37/html/search.php on line 63
$sql = mysql_query($query, $conn);
However when i replace this line with:
$sql = mysql_query($query, dbConn());
it gives no problems. when i write both the $link value and the $conn value to the page it both says somethign like: id resource #2.
Can someone tell me why i get this error? and how to solve it?
thx in advance.