我正在运行一个脚本来更新 MySQL 表,并且我一直在回显更新语句以帮助解决更新语句不起作用的原因。当我将 mysql 更新的回显查询复制并粘贴到 phpmyadmin 的 SQL 菜单中时,它运行良好,但是当我运行脚本时,更新查询不执行。我知道我已成功连接到数据库。有谁知道为什么更新语句复制并粘贴到 phpmyadmin 的 sql 选项卡中的回显版本会成功执行,而不是应该在回显语句之前的行执行的实际查询?这是我的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>