记录显示,但我可以在PHP中更新它

时间:2014-05-15 16:38:53

标签: php mysql

大家好,我可以通过将查询字符串的id传递到另一个页面来显示我的记录,但是我无法更新它,问题是当我点击更新时没有任何事情发生,它给我一个空白页面,没有印刷错误,有人能帮帮我吗?

  <?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;
    }


    }
    }

1 个答案:

答案 0 :(得分:0)

首先,当您获得空白页时,请检查错误日志。或者,如果您懒惰,请在文件开头添加此内容以获取错误消息。

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
?>

很难说,但只是快速查看代码,我发现您的$_GET$_POST混音存在问题。根据我收集的内容,由于您的SELECT有效,您可以在$_GET中发送数据,只有拥有UPDATE数据时才会执行$_POST数据块。

更改<form method="get">

的html <form method="post">

并更改select阻止内容以检查if( !empty($_POST['id'])) {