我有这样的表格:
<form action="addScript.php" methot="POST" enctype="multipart/form-data">
<tr>
<td>Produt title : </td><td><input type="text" name="title" id="title" /></td>
</tr>
<tr>
<td>Product description : </td><td><textarea rows="5" cols="40" name="description" id="description"></textarea></td>
</tr>
<tr>
<td>Price (USD $) : </td><td><input type="text" name="price" id="price" /></td>
</tr>
<tr>
<td>Profile Picture : </td><td><input type="file" name="profilepic" id="profilepic" /></td>
</tr>
<tr>
<td>Other pictures : </td><td>
<div id="pictures" style="border:1px solid black;"><table>
<tr><td>1</td><td><input type="file" id="pic1" name="pic1" /></td></tr>
<tr><td>2</td><td><input type="file" id="pic2" name="pic2" /></td></tr>
<tr><td>3</td><td><input type="file" id="pic3" name="pic3" /></td></tr>
</table>
</div>
</td>
</tr>
<tr>
<td></td><td><input type="submit" value="Add" /></td>
</form>
问题是即使我使用方法POST,当它调用addScript.php时,使用的方法实际上是GET,我的链接是www.domain.com/addScript.php?name=..&description=... etc.
如果我在php文件中使用$name=$_REQUEST['title'];
,我会收到此错误:Undefined index: title in /home/domain/public_html/addScript.php on line 13
。我该如何解决这个问题?
修改 这是我没有mysqli_connect();
的PHP$name=$_POST['title'];
$description=$_POST['description'];
$price=$_POST['price'];
$profilePic=$_FILES['profilepic']['name'];
$path="images/";
//move picures in images/ folder and get their path
$pic1=$_FILES['pic1']['name'];
$pictmp=$_FILES['pic1']['tmp_name'];
$moveResult=move_uploaded_file($pictmp, $path);
$pic2=$_FILES['pic2']['name'];
$pictmp=$_FILES['pic2']['tmp_name'];
$moveResult=move_uploaded_file($pictmp, $path);
$pic3=$_FILES['pic3']['name'];
$pictmp=$_FILES['pic3']['tmp_name'];
$moveResult=move_uploaded_file($pictmp, $path);
$pic1Path=$path.$pic1;
$pic2Path=$path.$pic2;
$pic3Path=$path.$pic3;
//insert info in database
$sql="INSERT INTO products ( name, description, price, profile_pic, pic1, pic2, pic3)
VALUES
('$name','$description','$price',$profilePic','$pic1Path','$pic2Path','$pic3Path')";
if(!mysqli_query($con,$sql)){
die("ERROR ".mysqli_error($con));
}
我总是得到这个错误
ERROR You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'images/','images/','images/')' at line 3
重新编辑:
现在我可以看到确认已回显,但是它会在我的error_log中填充这些错误,并且数据库中的列大部分都是空的。
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: title in /home/domain/public_html/addScript.php on line 13
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: description in /home/domain/public_html/addScript.php on line 14
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: price in /home/domain/public_html/addScript.php on line 15
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: profilepic in /home/domain/public_html/addScript.php on line 16
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic1 in /home/domain/public_html/addScript.php on line 20
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic1 in /home/domain/public_html/addScript.php on line 21
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic2 in /home/domain/public_html/addScript.php on line 24
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic2 in /home/domain/public_html/addScript.php on line 25
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic3 in /home/domain/public_html/addScript.php on line 28
[05-Feb-2014 15:01:12 UTC] PHP Notice: Undefined index: pic3 in /home/domain/public_html/addScript.php on line 29
重新重新修改
我在$ name之前的PHP文件中添加了var_dump($_REQUEST);
并得到了这个
array(7) { ["name"]=> string(4) "aaaa" ["description"]=> string(7) "aaaaaaa" ["price"]=> string(3) "555" ["profilepic"]=> string(7) "cr7.jpg" ["pic1"]=> string(9) "copac.jpg" ["pic2"]=> string(9) "close.png" ["pic3"]=> string(12) "obiectiv.jpg" } 1 product added
但DB中的列仍为空。
答案 0 :(得分:6)
您的表单中有拼写错误。您输入了methot
而不是method
:
<form action="addScript.php" methot="POST" enctype="multipart/form-data">
应该是
<form action="addScript.php" method="POST" enctype="multipart/form-data">
<强>更新强>
您在SQL查询中缺少引号:
('$name','$description','$price',$profilePic','$pic1Path','$pic2Path','$pic3Path')";
^^^^^
HERE
应该是
('$name','$description','$price','$profilePic','$pic1Path','$pic2Path','$pic3Path')";
^^^^^
HERE
答案 1 :(得分:3)
请检查“方法”的拼写