I'm trying to run 3 lines of the same code as seen below.I've also tried the W3Schools PHP mysqli_multi_query() Function but it gives me a syntax error and only the 1-st line of code works the ExistingWord1
I also read a couple of stackoverflow posts about this and this can't figure it out
<?php
include 'words.php';
include('../config.php');
$servername = DB_HOSTNAME;
$username = DB_USERNAME;
$password = DB_PASSWORD;
$dbname = DB_DATABASE;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
/*UTF-8 format*/
$conn->set_charset("utf8");
$sql = "UPDATE product_description SET name = REPLACE(name, '$ExistingWord1', '$ReplacerWord1') WHERE name LIKE '%$SearchWord1%';";
$sql = "UPDATE product_description SET name = REPLACE(name, '$ExistingWord2', '$ReplacerWord2') WHERE name LIKE '%$SearchWord2%';";
$sql = "UPDATE product_description SET name = REPLACE(name, '$ExistingWord3', '$ReplacerWord3') WHERE name LIKE '%$SearchWord3%';";
if ($conn->query($sql) === TRUE) {
echo "Products updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
This is the full Code that i am trying to run as by itself it only runs the 1st $sql =""
and ignores the other 2
as for the variables in the REPLACE
$ExistingWord1 words that are in the database name
$ReplacerWord1 replaces the ExistingWord1
'%$SearchWord1%' real database names
Thanks for the help guys
Everyone in this post was really helpful i really do appriciate it.