所以插入语句的所有内容都能完美运行。我知道数据库正在连接,因为我可以使用前两个语句从数据库中选择信息。我也知道execute_statment3有效,因为没有错误被打印掉,当它被放入sql时,语句按照应该的方式插入。因此,问题在于脚本和phpmyadmin之间的通信。请帮助我一直盯着这个问题两天,而且我很疯狂。
<?php
session_start();
$hostname = 'localhost';
$username = '####';
$password = '####';
$connection = mysql_connect($hostname, $username, $password)
or die ('Connection error!!!');
$database = '####';
mysql_select_db($database);
$uid = $_SESSION['ID'];
$album = $_POST['albumname'];
$description = $_POST['description'];
$filename = $_FILES["upload_file"]["name"];
$filetype = $_FILES["upload_file"]["type"];
$filesize = $_FILES["upload_file"]["size"];
$file_on_server = $_FILES["upload_file"]["tmp_name"];
if ($filetype == "image/jpeg") {
$file_copy_name = date(m.d.y_H.i.s) . ".jpg";
copy($file_on_server, "uploads/" . $file_copy_name);
print "<br>";
print "<img src = \"uploads/$file_copy_name\">";
print "<br>";
$ret = system("pwd");
$picture = "uploads/$file_copy_name";
}
$execute_statement = "SELECT * FROM ImageAlbums WHERE Album = '$album'";
$results = mysql_query($execute_statement) or die ('Error executing SQL statement!!!');
while($item = mysql_fetch_array($results))
{
$album2 = $item['Album'];
}
if ($album2 == $album)
{
$execute_statement2 = "SELECT * FROM ImageAlbums WHERE Album = '$album'";
$results2 = mysql_query($execute_statement2) or die ('Error executing SQL statement2!!!');
while ($row2 = mysql_fetch_array($results2)) {
$AID = $row2["AlbumID"];
}
$execute_statement3 = "INSERT INTO Images (`ImageID`, `AlbumID`, `Description`, `Extensions`) VALUES ('NULL', '$AID', '$description', '$file_copy_name')";
($execute_statement3) or die ('Error executing SQL statement3!!!');
}
print "<br>";
print "<br>";
print $execute_statement3;
print "<br>";
print "<br>";
print $AID;
print "<br>";
print "<br>";
print $picture;
?>
我正在为此脚本使用两个数据库,其中一个数据库名为ImageAlbums,有两列名为AlbumID和Album(AlbumID是主键)。第二个表称为Images,有四列ImageID(主键),AlbumID(外键),描述和扩展。
答案 0 :(得分:1)
您没有运行语句
($execute_statement3) or die ('Error executing SQL statement3!!!');
尝试:
mysql_query($execute_statement3);
另外,请确保您转义所有变量。
答案 1 :(得分:0)
确保您在php脚本中连接的用户具有insert语句的权限。您可能正在使用仅具有select privs的数据库用户...