Hello,
I know I shouldn't use mysql_.
So I have a mysql_query which updates my table (for a hit counter).
However, when I open the page, I get to see this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' WHERE shorturl='example'' at line 1
My code:
<?php
include ('config.inc.php');
$connection = mysql_connect($host, $user, $password);
mysql_select_db($database, $connection);
$shorturl = $_GET['shorturl'];
$shorturl = rtrim($shorturl, '/');
$query = mysql_query('SELECT longurl,count FROM `' . $prefix . 'urls` WHERE shorturl=\'' . $shorturl . '\'');
$array = mysql_fetch_array($query);
$num_rows = mysql_num_rows($query);
if($num_rows > 0) {
mysql_query('UPDATE `' . $prefix . 'urls` SET count=\'' . $array['count']+1 . '\' WHERE shorturl=\'' . $shorturl . '\'');
echo mysql_error();
//header('Location: ' . $array['longurl']);
} else {
header('Location: http://short.sydcul.com/index.php?message=' . rawurlencode('The short URL you submitted was not found. Why not create it below?'));
}
mysql_close($connection);
?>
The problem is at line 14. I commented out line 16 for debugging.
I checked everything, compared this to my other UPDATE-queries I used, nothing special. I also tried to remove the \'
at the count (which is getting read as a '
, I know I could use "
, but I just prefer '
because of PHP reading it in a different way), but that will not solve it.