MySQL query
| From: | Jason Giangrande | Date: | Wed, 28 Jan 2004 04:05:22 +0000 |
| Subject: | MySQL query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-176002@lists.php.net to get a copy of this message | ||
I have the following query.
UPDATE link SET hits = hits+1 WHERE website_link = '$link'
$link is the website link that was clicked on.
The query works fine. The problem is if $link is a website that does
not exist in the database mysql_query(); still returns true even though
nothing was updated. Why is this, and anyone have any suggestions on
the easiest way to check to see if $link exists in the database before
updating it?
Here's the code. db_error() is a function that calls mysql_error() and a
few other things.
$link = $_GET['link'];
$query = "UPDATE link SET hits = hits+1 WHERE website_link = '$link'";
$result = @ mysql_query($query, $connection) or db_error();
var_dump($result); // True even if $link does not exist in database.
header("Location: $link");
die();
** db_error() function **
function db_error() { // Dies with fatal error
global $db_name;
if (mysql_error()) {
die("Error " . mysql_errno() . ": " . mysql_error());
} else {
die("Could not connect to database, $db_name");
}
}
--
Jason Giangrande <jason@giangrande.org>
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc