I'm not sure if you solved this or not, but I'm submitting the following answer just in case.
This query is failing for a few reasons.
mysqli_query($con, 'UPDATE action SET watch = watch+1 WHERE title = $title ');
^^^^^^ ^^^^^^
Firstly, you're using a MySQL reserved word called "action", then $title
stands at being a string.
You need to wrap the "action" column name in ticks and $title
in quotes, and possibly escaping that data should it contain anything that MySQL will complain about, such as apostrophes for instance.
I.e.:
$title = mysqli_real_escape_string($con, $title);
mysqli_query($con, "UPDATE `action` SET watch = watch+1 WHERE title = '$title' ");
Then in comments you added $con=mysqli_connect("host","db","pass");
The syntax is:
- host
- username
- password (if one is required)
- database
References:
Procedural style example, from the manual:
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
echo 'Success... ' . mysqli_get_host_info($link) . "\n";
mysqli_close($link);
?>
Add or die(mysqli_error($con))
to mysqli_query()
.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
If you want to check if your query was truly successful, use affected_rows()
.
However, your present code is open to SQL injection. Use prepared statements, or PDO with prepared statements, they're much safer.
Footnotes:
- It's unsure as to where/how the
$title
variable is defined as, but seeing a word as such, tells me it's most likely a string and you may need to elaborate on that.