-1
大家好我能顯示我的記錄通過查詢字符串傳遞一個id到另一個頁面,但我無法更新它,問題是,當我點擊在更新沒有任何事情發生,它返回給我一個空白頁,並沒有打印錯誤,請有人可以幫我嗎?記錄顯示,但我可以更新它在php
<?php
require 'db2.php';
$id = null;
if (!empty($_GET['id'])) {
$id = $_REQUEST['id'];
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
$q = mysqli_query($dbc,"SELECT * FROM movie WHERE MovieID = '$id' ");
while($r=mysqli_fetch_array($q))
{
$title = $r["Title"];
$tag = $r["Tag"];
$year = $r["YEAR"];
$cast = $r["Cast"];
$comment = $r["Comment"];
$IDBM = $r["IMDB"];
}
}
在這個階段,代碼顯示每一個信息,我需要,下面的階段是我有一個問題,我不能夠得到對ID和進行更新時,點擊更新按鈕
elseif (!empty($_POST) and !empty($_GET['id'])) {
// keep track post values
$cast = $_POST['cast'];
$title = $_POST['title'];
$comment =$_POST['comment'];
$year = $_POST['year'];
$tag = $_POST['tags'];
$IDBM = $_POST['idbm'];
$cast = htmlspecialchars($cast);
$title = htmlspecialchars($title);
$comment = htmlspecialchars($comment);
// validate input
$valid = true;
if (empty($cast)) {
$castError = 'Please enter Cast';
$valid = false;
}
if (empty($title)) {
$titleError = 'Please enter Title';
$valid = false;
}
if (empty($comment)) {
$commentError = 'Please enter Comment';
$valid = false;
}
if ($valid) {
$id = $_REQUEST['id'];
$valid_formats = array("jpg", "png", "gif", "bmp");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024))
{
$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
mysqli_query($dbc,"UPDATE movie SET Title='$title',Year = '$year',Cast='$cast',Cover='$actual_image_name',Tag='$tag',Comment='$comment',IMDB ='$IDBM' WHERE MovieID=".$id);
header ("Location: index.php");
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
}
}
你是如何傳遞的ID來翻頁?隱藏的輸入字段?請求參數?更新表單(html)的外觀如何? –
@NawedKhan,查詢字符串,我有一個按鈕更新,當它點擊更新時,它應該進行驗證檢查之前,檢查是否有任何記錄丟失,然後使用id從查詢字符串進行更新,顯示信息從查詢字符串工作,但不更新 – user3626062
趕上並檢查mysqli_query的結果。如果它是FALSE,則會出現錯誤,否則應該爲TRUE。 http://us1.php.net/mysqli_query 如果出現錯誤,可以使用 echo mysqli_error($ dbc); –