Can anyone help me please? There are 2 queries. How join them to 1 query?
$sql1="UPDATE gallery
SET namesk='$_POST[namesk]', nameen='$_POST[nameen]', descriptionsk='$_POST[descriptionsk]', descriptionen='$_POST[descriptionen]', date='$_POST[date]', url1='$_POST[url1]'
WHERE namesk='$_GET[namesk]'";
$sql2="UPDATE photos
SET namesk_gallery='$_POST[namesk]'
WHERE namesk_gallery='$_GET[namesk]'";
They works, but I would like to know, how to create one query. Thanks very much.
Its easy to do (I use mysqli functionality for this):
$conn = mysqli_init();
$conn->real_connect("hostname", "username", "password", "dbname");
$query = "
UPDATE gallery
SET namesk='{$_POST['namesk']}', nameen='{$_POST['nameen']}', descriptionsk='{$_POST['descriptionsk']}', descriptionen='{$_POST['descriptionen']}', date='{$_POST['date']}', url1='$_POST[url1]'
WHERE namesk='{$_GET['namesk']}';
UPDATE photos
SET namesk_gallery='{$_POST['namesk']}'
WHERE namesk_gallery='{$_GET['namesk']}';
";
$result = $conn->multi_query($query);
But make sure that after each of your queries you use the semi-colon (;
) to separate them.
Edits
Added variable encapsulation for the $_POST
and $_GET
(don't know how you are using both at once...)
This answer gives a full one query version, I'd reproduce but that seems a waste when the answer is just there and with a very good explanation