我想通過POST方法創建表單並檢索另一個PHP文件上的表單值。通過POST方法傳輸表單輸入
但不幸的是,它似乎並沒有工作。下面
的形式輸入文件
<form action="uploadimage.php" method="POST" enctype="multipart/form-data">
<div align="center"><table border=0>';
echo"<tr><td>Caption: </td><td><input type='text' name='caption'></td></tr>
<tr><td>Album</td><td>";
$Query='SELECT * FROM `gallery`';
$result=mysqli_query($connection,$Query);
echo'<select name="albums">';
$count=0;
$previous=-1;
while($data=mysqli_fetch_array($result))
{
if($previous<$data['album'])
{
echo "<option value=".$data['album'].">".$data['album']."</option>";
$previous=$data['album'];
}
if($count<=$data['album'])
{
$count=$data['album']+1;
}
}
echo "<option value='.$count.'>New Album</option>";
echo"</select></td></tr>
<tr><td>Picture: </td><td><input type='file' name='photo'></td></tr>
<tr><td></td><td><input type='submit' name='upload_btn' value='upload'></td></tr>
</table></div>
</form>
不介意其他的代碼,我只是擔心表單的輸入值的轉移。
這裏是接收在另一個PHP文件
require_once"connection.php";
$target_Path='img/displays/';
$caption=$_POST['caption'];
$albums=$_POST['albums'];
$target_Path = $target_Path.basename($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'], $target_Path);
$withoutExt = preg_replace("/\\.[^.\\s]{3,4}$/", "", $target_Path);
mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id` ,`album`,`name`,`path`)VALUES (NULL,'".$albums."','".$caption."','".$withoutExt."')");
和錯誤,我接收是如下
通知的形式的值的代碼:未定義指數:字幕在C: \ wamp \ www \ ETT Logo \ Controlpanel \ uploadimage.php on line 12
我收到上面的錯誤表單中的所有輸入。並且這些值沒有被傳送。
我沒有看到一個'
'標籤 – RiggsFolly我還沒有看到任何錯誤檢查有關文件上傳[參見手冊] (http://php.net/manual/en/features.file-upload.php) – RiggsFolly
您的腳本存在[SQL注入攻擊]的風險(http://stackoverflow.com/questions/60174/how-can-看看發生了什麼事[Little Bobby Tables](http://bobby-tables.com/)即使 [如果你正在逃避投入,它不安全! ](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) 使用[prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly