I'm trying to do an update and insert, in both cases I've got to do a select on the table first, which works. But when I come to do the update and insert queries they don't do anything.
I'm calling mysql_connect each time (any problem with doing this? my host doesn't have persistent connections). I've had a bit of a similar problem on other pages.
eg.
$select = "SELECT Hits FROM postcardhits WHERE PhotoID = '$photoID'";
@ $db = mysql_connect("localhost", "xxx", "xxx"
or die ('I cannot connect to the database because: ' . mysql_error());
$result = mysql_db_query("xxx", $select);
//this code above seems to be working.
// if the number of rows is GT 0... and it is...
$row=mysql_fetch_object($result);
$hits=$row->Hits;
$newHits=$row->Hits + 1;
$sql="UPDATE postcardhits SET Hits = '".$newHits."' WHERE PhotoID ='$photoID'";
@ $db = mysql_connect("localhost", "xxx", "xxx"
or die ('I cannot connect to the database because: ' . mysql_error());
$result=mysql_query($sql);
NOTE: I originally had '$newHits', until I saw an example in a book in the form '".$newHits."', so I've tried both forms -- no results either way.
I've checked the $sql string, everything is coming out just fine, I can copy and paste it into phpmyadmin and it runs the SQL just fine. But from my PHP page it does nothing.
I seem to sometimes (not all the time) have a problem when I am making more than one call to the database on the same page. But it's nothing consistent, for example in this set I've got 2 calls to the DB, the first is fine, 2nd doesn't work. In another set I've got the first 2 calls working, 3rd does nothing.
Anyone know what's going on here?
The New Zealand Site
I'm calling mysql_connect each time (any problem with doing this? my host doesn't have persistent connections). I've had a bit of a similar problem on other pages.
eg.
$select = "SELECT Hits FROM postcardhits WHERE PhotoID = '$photoID'";
@ $db = mysql_connect("localhost", "xxx", "xxx"
or die ('I cannot connect to the database because: ' . mysql_error());
$result = mysql_db_query("xxx", $select);
//this code above seems to be working.
// if the number of rows is GT 0... and it is...
$row=mysql_fetch_object($result);
$hits=$row->Hits;
$newHits=$row->Hits + 1;
$sql="UPDATE postcardhits SET Hits = '".$newHits."' WHERE PhotoID ='$photoID'";
@ $db = mysql_connect("localhost", "xxx", "xxx"
or die ('I cannot connect to the database because: ' . mysql_error());
$result=mysql_query($sql);
NOTE: I originally had '$newHits', until I saw an example in a book in the form '".$newHits."', so I've tried both forms -- no results either way.
I've checked the $sql string, everything is coming out just fine, I can copy and paste it into phpmyadmin and it runs the SQL just fine. But from my PHP page it does nothing.
I seem to sometimes (not all the time) have a problem when I am making more than one call to the database on the same page. But it's nothing consistent, for example in this set I've got 2 calls to the DB, the first is fine, 2nd doesn't work. In another set I've got the first 2 calls working, 3rd does nothing.
Anyone know what's going on here?
The New Zealand Site