嗨,大家好我正在一個項目,我有一個student_edit.php文件,更新學生 詳細信息我所有的數據更新成功,但有一個問題,當我更新只能說兩個領域和不是所有的圖像是空白的,我的領域更新成功。無法更新圖像在PHP和MYSQL
我在做什麼是我顯示學生圖片,除此之外,我有另一個輸入字段來瀏覽圖像更新圖像。我想要的很簡單,如果我不更新圖像,而是我更新其他字段圖像應該仍然存在,而不是變成空白。
必需的代碼段是這樣的:
<?php
$file_name = $_FILES['picture']['name'];
$tmp_name = $_FILES['picture']['tmp_name'];
if (copy($tmp_name, "images/" . $file_name)) {
$picture = "images/" . $file_name;
}
if (!isset($_POST['picture'])) {
$res = mysql_query("UPDATE student SET `id`='$id',`branch_id`='$branch_id',`class_id`='$class_id',`section_id`='$section_id',`roll_number`='$roll_number',`student_name`='$student_name',`father_name`='$father_name',`dob`='$dob',`student_address`='$student_address',`gender`='$gender',`status`='$status',updated=now() WHERE id='$id'") or die(mysql_error());
}
else {
$res = mysql_query("UPDATE student SET `id`='$id',`branch_id`='$branch_id',`class_id`='$class_id',`section_id`='$section_id',`roll_number`='$roll_number',`student_name`='$student_name',`father_name`='$father_name',`dob`='$dob',`student_address`='$student_address',`gender`='$gender',`status`='$status',`picture`='$picture',updated=now() WHERE id='$id'") or die(mysql_error());
}
?>
他們是畫面區域在哪裏調用圖片
<p>
<label for="picture"><strong>Picture:</strong> </label>
<a href="#"><img src="<?php echo $rec['picture'];?>" width="100" height="100"/></a>
<input name="picture" type="file" value="">
</p>
他們是畫面區域在哪裏調用圖片
<p>
<label for="picture"><strong>Picture:</strong> </label>
<a href="#"><img src="<?php echo $rec['picture'];?>" width="100" height="100"/></a>
<input name="picture" type="file" value="">
</p>
請不要將'mysql_ *'函數用於新代碼。他們不再被維護,社區已經開始[棄用流程](http://goo.gl/KJveJ)。請參閱[**紅框**](http://goo.gl/GPmFd)?相反,您應該瞭解[準備好的語句](http://goo.gl/vn8zQ)並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli的)。如果你不能決定,[本文](http://goo.gl/3gqF9)將有助於選擇。如果你關心學習,[這裏是很好的PDO教程](http://goo.gl/vFWnC)。 – 2012-07-21 20:31:24
感謝您的推薦! – user1313942 2012-07-21 20:37:53