I have got an odd problem with a MySQL update statement for which I would very much appreciate any advice.
The scripts have been working fine for a while but suddenly they're all giving me the following error:
"Warning: mysql_query(): supplied resource is not a valid MySQL-Link resource in /var/www/html/brewers_hill/admin/content1_update.php on line 12"
The script uses db_connect.inc to connect to MySQL. This include works fine with all the SELECT queries on the site but not any of the UPDATE scripts on the site.
Also when I copy the contents of the db_connect.inc into the main script the UPDATE statement then works.
Here's a script, typical of the ones that have mysteriously stopped funtioning:
<?PHP
session_start();
if (session_is_registered("uname") and ($accesstype=='super_user' OR $accesstype=='admin' OR $accesstype=='department')){
require('db_connect.inc');
require('header.inc');
#SQL Query
$query ="UPDATE content1 SET heading=\"$heading\", body=\"$body\", pic_1=\"$pic_1\", pic_2=\"$pic_2\", user_id=\"$edit_id\" WHERE id=\"$id\" ";
$result=mysql_query($query, $dbh)
or die (mysql_error());
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="218">
<tr>
<td><br>
<img src="interface/<?php echo("$article"); ?>.gif" >
<br>
</td>
</tr>
<tr>
<td class="brewersBoldRedLg" height="74">
<div align="center">Upload Complete</div>
</td>
</tr>
<tr>
<td height="104">
<div align="center"><img src="interface/tick.jpg" width="114" height="96"></div>
</td>
</tr>
<tr>
<td height="104">
<div align="center">
<p><span class="brewersBoldRedMed">Please check on the main site to verify
any changes or click Admin to return to the panel</span><br>
<br>
<br>
<a href="index.php"><img src="interface/admin_button.jpg" width="68" height="49" border="0"></a>
<a href="http://www.brewershill.co.uk"><img src="interface/main_button.jpg" width="51" height="48" border="0"></a></p>
<p> </p>
</div>
</td>
</tr>
<tr>
<td height="104"> </td>
</tr>
</table>
<?PHP
require('footer.inc');
mysql_close();
} else { header("Location:no_auth.php?section=deny");
exit();
} ?>
Here's the db_connect.inc script:
<?PHP
global $dbh;
$user = "####";
$pass = "####";
$hostname = "####";
$conn = mysql_connect($hostname, $user, $pass)
or die("Unable to connect to MySQL");
$dbh = mysql_select_db("brewers_hill", $conn)
or die("Could not select database");
?>
Why do you think $dbh isn't working when it's part of the include?
There is a SELECT query in header.inc that uses $dbh in the same way. Could this be interfering?
I hope I've provided enough information. Many thanks in advance for any assistance.
Regards,
Jason (N. London, UK)