skip to Main Content

I have been trying to update a field in database using php, everytime I run the script there is no effect on the table. Here’s how my code looks :

$sql="UPDATE users set sentMsg = $msg+1 where username = '$username' ";
$result = $link->query($sql);

where $link is the connection variable which is working fine with other queries.
Here’s the table structure.
enter image description here

The $result variable is returning true.
I am unable to understand where the actual problem is.

2

Answers


  1. try this;

    $newCount = $msg+1;
    
    $sql="UPDATE users set sentMsg = $newCount where username = '$username' ";
    $result = $link->query($sql);
    

    or

    $sql="UPDATE users set sentMsg = ".($msg + 1)." where username = '$username' ";
    $result = $link->query($sql);
    
    Login or Signup to reply.
  2. Try this

    $sql="UPDATE `users` SET `sentMsg` =".($msg+1)." WHERE `username` ='".$username."'";
    
    $result = mysqli_query($link,$sql);
    

    Thats what i could make out of your code till now.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search