到目前为止,我的脚本可以上传图片,将网址存储在数据库中。我不知道如何为标题和标签添加其他两个文本字段。
if($_POST["action"]=="Submit")
{
$folder="../../images/images_Submitted/";
move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
$fileName = $_FILES["filep"]["name"];
echo "<p align=center>File ".$fileName." loaded...";
$result = mysql_connect("*****", "*****", "*****") or die ("Could not save image name Error: " . mysql_error());
mysql_select_db("pwnweb") or die("Could not select database");
$SQLURL = "INSERT INTO photos (URL) VALUES('/images/images_Submitted/" . $fileName . "')";
echo "INSERT INTO photos (URL) VALUES('/images/images_Submitted/" . $fileName . "')";
mysql_query($SQLURL);
if($result)
{
echo " Image name saved into database";
}
else
{
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}
这是我的表格:
<form action="/../scripts/php/submitButtonPressed.php" method=post enctype="multipart/form-data">
Title: <input type="text" name="title" size=45><br>
File: <input type="file" name="filep" size=45><br>
Tags: <input type="text" name="tags" size=45><br>
<input type=submit name=action value="Submit" size=45>
</form>
答案 0 :(得分:1)
与@ user1978142一样,您可以尝试使用$_POST
。我会尝试深入探讨:
就像$_FILES
一样,$_POST
是一个数组,它通过表单中设置的名称存储从HTML传递给PHP的元素的值。要检索所述值,请使用以下命令访问该数组:
$_POST['
输入名称 ']
然后将值存储到变量中。
在您的代码中应该是:
$title = $_POST['title'];
$tags = $_POST['tags'];
最后,在查询中添加它们:
"INSERT INTO photos (title, tags) VALUES ('".$title."', '".$tags."')"