Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_query() issue

Status
Not open for further replies.

IDTstudios1

Programmer
Aug 8, 2004
72
US
I cannot figure this out.

This code:

$mysql_insert = mysql_query($insert, $mysql_link);
if (!$mysql_insert) { die( "Please notify the admin that the script is connecting to the database, but not inserting the information ".mysql_error());
}

is giving me this error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/solittle/ on line 97
Please notify the admin that the script is connecting to the database, but not inserting the information
 
here's the all the code involved if it helps:

$DB_username = "solittle";
$DB_password = "19633385";
$DB_name = "idt";

$mysql_link = mysql_pconnect( "localhost", "$DB_username", "$DB_password");

if (!$mysql_link) { die( "Unable to connect to MySQL server");
}

$insert = "INSERT INTO logins(datetime, ip_address, username, password, correct, incorrect) ".
"VALUES('$datetime', '$ip_address', '$username', '$password', '0', '1')" or die("Bad query: ".mysql_error());

$mysql_insert = mysql_query($insert, $mysql_link);
if (!$mysql_insert) { die( "Please notify the admin that the script is connecting to the database, but not inserting the information ".mysql_error());
}
 
A mysql_select_db() statement needs to be issued before the query, so MySQL knows which database to open.
 
I thought of that, but the information actually IS being put into the database. would not having that statement cause this if the data is being inserted?
 
why are you using die() when just building the sql string?
Code:
 or die("Bad query: ".mysql_error());


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
i completely overlooked that. I'll take it out and see what happens.
 
INSERT INTO logins(datetime, ip_address, username, password, correct, incorrect) ".
"VALUES('$datetime', '$ip_address', '$username', '$password', '0', '1')"

shouldnt it be:

"INSERT INTO logins(datetime, ip_address, username, password, correct, incorrect) VALUES('".$datetime."', '".$ip_address."', '".$username."', '".$password."', '0', '1')"

As far as I know variables wont be parsed unless they're enclosed double quotes.
Another thing worth mentioning is if the amount of columns equals the amount of values being inserted you can just do
"INSERT INTO logins VALUES('".$datetime."', '".$ip_address."', '".$username."', '".$password."', '0', '1')"

 
captlid,
the existing syntax looks fine. the entire sql string is enclosed in double quotes. this is also how i write mine.


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top