Invalid mysql_query argument.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
PacX
Forum Newbie
Posts: 3
Joined: Tue Feb 15, 2005 7:00 pm

Invalid mysql_query argument.

Post by PacX »

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:

Code: Select all

<?php
function dbConn()&#123;
$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))&#123;
    echo "ERROR: <br /><br />";
    echo mysql_error();
&#125;
return $link;
&#125;

$conn = dbConn();
later on in the script, i use this to save the results of a query to $sql.

Code: Select all

$userSearchReq = " WHERE (Username = '&#123;$_POST&#1111;'searchUser']&#125;')";
$query = "SELECT * FROM user_info" . $userSearchReq;
$sql = mysql_query($query, $conn); 
if(!$sql)&#123;
echo "Error: <br />";
echo mysql_error();
exit();
&#125;

// ____Here comes the code for writing all matches to a table. _____
And later on i close the connection with:

Code: Select all

mysql_close($conn);
There's also a function which writes the html search form to the page.
I get an error after i submitted that form.
Error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/web37/html/search.php on line 63
63 is this line:
$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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sounds like $conn was closed by that point.
PacX
Forum Newbie
Posts: 3
Joined: Tue Feb 15, 2005 7:00 pm

Post by PacX »

ah, yes ii had to place the $conn = dbConn() somewhere else.
Post Reply