How to execute two MySQL queries?

I want to save the path to the image file and the image name in one table, but, of course, separate fields. How can I execute it correctly? I am sure there is something significantly wrong in the code below, but I cannot notice it. Thank.

$sess_userid = mysql_real_escape_string($_SESSION['userid']);
$Image = mysql_real_escape_string($_FILES['file']['name']);
$PortraitPath = mysql_real_escape_string('profileportraits/' . $_FILES['file']['name']);

$query  = "UPDATE Members 
             SET PortraitPath = '$PortraitPath' 
           WHERE fldID='$sess_userid'";

$query2 = "UPDATE Members 
              SET Image = '$Image' 
            WHERE fldID='$sess_userid'";  

$result = mysql_query($query) or trigger_error(mysql_error().$query);
$result2 = mysql_query($query2) or trigger_error(mysql_error().$query2);
+3
source share
2 answers

You can update multiple fields in the same table at the same time.

 $query  = "UPDATE Members 
            SET PortraitPath = '$PortraitPath',
                Image = '$Image'
            WHERE fldID='$sess_userid'"; 


mysql_query($query) or trigger_error(mysql_error().$query);
+7
source

Use a comma like this:

UPDATE Members 
   SET PortraitPath = '$PortraitPath', 
       Image = '$Image' 
 WHERE fldID = '$sess_userid'
+2
source

Source: https://habr.com/ru/post/1755836/


All Articles