SQL: mysqli doesn't work, but neither does mysql_ in part
Posted: Mon Apr 13, 2009 7:23 pm
Hi everyone,
I've run this code through for a few hours, then I ran it through RapidPHP with no syntax errors, and I narrowed it down first to an error in using "mysqli" instead of "mysql". I replaced mysqli with mysql and it still caused errors...
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/findvj/public_html/jsr.php on line 21
Could not run query:
I'm suspecting it's to do with the contents of the table, things not quite matching up from the other end... but if something stands out could you please offer your insights?
Thanks much,
Lionel
I've run this code through for a few hours, then I ran it through RapidPHP with no syntax errors, and I narrowed it down first to an error in using "mysqli" instead of "mysql". I replaced mysqli with mysql and it still caused errors...
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/findvj/public_html/jsr.php on line 21
Could not run query:
I'm suspecting it's to do with the contents of the table, things not quite matching up from the other end... but if something stands out could you please offer your insights?
Thanks much,
Lionel
Code: Select all
<?php
$user_name = "ZZZZZ";
$password = "XXXXXX";
$database_name = "XXXX";
$table_name = "OIOIO";
$key = $_POST["avikey"];
$full_name = $_POST["full_name"];
$dbh = mysql_connect("localhost", $user_name, $password, $database_name);
if (!$dbh)
{
die("Not connected : " . mysql_error($dbh));
}
else
{
$query = "SELECT * FROM `$table_name` WHERE aviname = '$key'";
$result = mysql_query($dbh,$query);
if (!$result)
{
echo 'Could not run query: ' . mysql_error($dbh);
}
else
{
$row = mysql_fetch_row($result);
if ($row >= 1)
{
echo ("key_in_list");
}
else
{
$query = "
INSERT INTO `$database_name`.`$table_name` (
`avikey`,
`full_name`
)
VALUES (
'$key', '$full_name')";
$result = mysql_query($dbh,$query);
echo ("new_key_added");
}
}
mysql_close($dbh);
}
?>