我已经写出了脚本,它似乎在我的测试服务器上运行得很好,但是当我尝试在我的实时服务器上使用它时,它不会将sql信息插入到表中。
这里是剧本:
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$title=$_POST['title2'];
$description=$_POST['description'];
$uploaded = $_POST['uploaded'];
$target = "../../projects/forms/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
$result=MYSQL_QUERY("INSERT INTO $tbl_name(title, description, target) ". "VALUES ('$title', '$description', '$target')");
$id= mysql_insert_id();
print "File ID: <b>$id</b>";
print "Title: <b>$title</b>";
print "Description: <b>$description</b>";
print "File Name:</b>$target";
print "To upload another file Click Here<br>";
答案 0 :(得分:0)
由于某种原因,您无法将数据插入数据库:
以及其他几种可能性。
通过在查询后调用mysql_error(),您可以清楚地看到出现了什么问题。
$result=MYSQL_QUERY("INSERT INTO $tbl_name(title, description, target) ". "VALUES ('$title', '$description', '$target')");
if (!$result){
echo mysql_error();
}
这与问题没有任何关系,但是你应该总是在将它们放入查询之前转义通过GET和POST获得的数据!否则,你的应用程序中会出现一个闪亮的安全漏洞。
$title=mysql_real_escape_string($_POST['title2']);
$description=mysql_real_escape_string($_POST['description']);
$uploaded = mysql_real_escape_string($_POST['uploaded']);