0

guys

I don't know why but php convert my value into 0 each time.

So, i have video table. Inside i have a row called like and dislike. Lets say i have 10 dislike.

Every time i check previously value like that:

$sql = "SELECT * FROM video WHERE video_id = '$id'";
    $result = mysqli_query($conn, $sql);
    while($row = $result->fetch_assoc()){
        $like=$row['vid_like'];
        $dislike=$row['vid_dislike'];

and i echo dislike i got 10 in return

Just after that i do that for increase dislike:

$dislike1= $dislike +1;
echo "dis = {$dislike1}";
$sqla = "UPDATE video SET vid_dislike='$dislike1' AND vid_like='$like' WHERE video_id = '$id' ";
mysqli_query($conn, $sqla);

my echo result is 11. But when i check table after that query, my dislike value is set to 0...

Piotr Mirosz
  • 846
  • 9
  • 20
  • 3
    UPDATE query doesn't use AND like that. Need to use comma. – Ultimater Mar 10 '19 at 23:11
  • Just in case you are not aware, these queries are vulnerable to SQL injection. If you want to know more, [this link](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) may be useful. – Travis Britz Mar 10 '19 at 23:17
  • 1
    Your query should be `UPDATE video SET vid_dislike='$dislike1', vid_like='$like' WHERE video_id = '$id' ";` note `,` in place of `AND` – Nick Mar 10 '19 at 23:57

1 Answers1

0

Your update query is not well formatted.

It must look like this :

UPDATE t1 SET col1 = col1 + 1, col2 = col1;

See documentation.

Here you wrote "AND" instead of a comma, which is by the way useless in this case since the second part is vid_like='$like' where $like value didn't change.

PHPnoob
  • 586
  • 3
  • 7