我有一個站點的管理端的這個簡短的腳本,將上傳和圖像或上傳鏈接到數據庫。我最近把這個站點從一個hostpapa服務器移到了一個godaddy服務器。這個腳本在hostpapa上效果很好。導入到godaddy服務器後,只能上傳圖片工作。上傳一個鏈接失敗,id返回0.它很奇怪,因爲auto_increment被設置並且上傳圖片證明auto_increment工作得很好。不知道爲什麼id爲鏈接上傳返回0,並且當我嘗試上傳鏈接時沒有任何內容插入到數據庫中。新的數據庫導入,mysql_insert_id()返回0
include '../connect.php';
if ($_POST['upload'])
{
//get file attributes.
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$title = $_POST['title'];
$url = $_POST['url'];
$type = $_POST['type'];
if ($name)
{
$location = "imgs/$name";
$dir = "../imgs/$name";
move_uploaded_file($tmp_name,$dir);
$query = mysql_query("INSERT INTO `links` VALUES ('','$title','','$location','$type')");
//last id
$id = mysql_insert_id();
echo $id,$location,$title;
die ("Image successfully uploaded.");
}
//this bit below is what doesn't work as it should.
$query = mysql_query("INSERT INTO `links` VALUES ('','$title','$url','','$type')");
//last id
$id = mysql_insert_id();
echo $id,$url,$title;
die ("Link successfully loaded.");
}
檢查mysql錯誤。 –