I am running a script to update a MySQL table, and I have been echoing the update statement to help troubleshoot why the update statement was not working. When I copy and paste the echoed query for the mysql update into the SQL menu in phpmyadmin, it works perfectly, but when I run the script the update query does not execute. I know I have successfully connected to the database. Does anyone know why an echoed version of the update statement copy and pasted into the sql tab of phpmyadmin would execute successfully, but not the actual query that is supposed to be executed the line before the echoed statement? Here is my php:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
</head>
<body>
<?php
$user = 'tunemashercom';
$pass = 'password';
$host = 'tunemashercom.ipagemysql.com';
$db_name = 'user_library';
@ $db = mysqli_connect($host, $user, $pass, $db_name);
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database.';
exit;
}
$oldsongs = $_POST['oldsongs'];
$newsongs = $_POST['newsongs'];
$count = count($newsongs);
$count2 = count($oldsongs);
echo "COUNT 1: ".$count." - COUNT 2: ".$count2."<br />";
for($i=0;$i<=$count;$i++){
$newtitle = $newsongs[$i]["song"];
echo $newtitle." - ";
if($newtitle == ""){
echo "NO NEW TAGS<br />";
}
else{
$title = $oldsongs[$i]["title"];
echo $title."<br />";
$artist = $oldsongs[$i]["artist"];
$album = $oldsongs[$i]["album"];
$newartist = $newsongs[$i]["artist"];
$newalbum = $newsongs[$i]["album"];
$mbid = $newsongs[$i]["mbid"];
$insert = "UPDATE collection SET song='".$newtitle."', artist='".$newartist."', album='".$newalbum."', gille_id='".$mbid."' WHERE song='".$title."' AND artist='".$artist."' AND album='".$album."'";
$results = $db->query($insert);
echo $insert."<br />";
}
}
mysqli_close($db);
?>
</body>
</html>