php mysql更新表插入Php代码[关闭]

      $sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";

Where "Doe" is must be a Php code without Php open and close tags

I want this to update in mysql database. How can i do this? This didnt work because of errors. Ive tried mysql escape string but this didnt work.

I have tried this

          $nee = '$variable; if ($conn->query($sql) === TRUE) { echo 
           "Record updated successfully";';

          $sql10 = "update wp_".$snippet."_xyz_ips_short_code 
           SET content='".$nee."' WHERE id=1";

Update:

Above code works. I had tried this also a while Ago but i think the errors were because of New lines. I have the Php code in 1 line now. It works now.

You have to concat your string variable into your query string.

Something like this:

$sql = "UPDATE MyGuests SET lastname = '" . $my_variable . "' WHERE id = 2";