更新id =%d的SQL语句不起作用

时间:2017-10-10 01:21:17

标签: php html sql

嗨,由于某种原因我的更新语句不起作用,很可能是因为id =%d,它没有得到我认为的语句的id,但它找到了id,因为它列在url中(如下所示) 。有什么问题吗?

这适用于我为id插入一个数字,例如:id = 77,所以很可能问题是%d我怎样才能找到%d的id?

http://localhost/test/edit.php?id=77

<?php

        ob_start();
        session_start();

        include_once 'logindb.php';
        $conn = new mysqli($hn, $un, $pw, $db);
        if ($conn->connect_error) die($conn->connect_error);

        if((isset($_POST['submit']))){
        if((!isset($_POST['title'])) || (!isset($_POST['times'])) ){
               echo "All values must be set"; 
            }
           else{

                $title = $_POST['title'];
                $times = $_POST['times'];
                $film_id = $_GET['id'];

                $upfile = 'Uploads/posters/'.$_FILES['userfile']['name'];                
                if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upfile)){
                    echo "File moved into folder";

                    header( "Location: index.php" ) ;
                }
                else{
                    echo "Problem: could not move image file to destination directory";
                }


                 $upfile2 = 'Uploads/trailers/'.$_FILES['userfile2']['name'];


                $format1 = "UPDATE films SET titles = '$title', ftimes = '$times', poster = '$upfile', trailer = '$upfile2' WHERE id = %d";

                $query = sprintf($format1, $film_id );


               $result = mysqli_query($conn, $query)
                    or die("Error in query: ". mysqli_error($conn));                

    }   

        }


 ?>

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Empire.css"/>
<script type="text/javascript" src="script.js"> </script>

<title>Movie Form</title>
</head>
<body class="formola">

<div class="form-style-5">

                <p class="top"> List Movies </p>
            <form method = "post" action="edit.php" enctype="multipart/form-data">
                <fieldset>
                    <legend><span class="number">1</span> Details </legend>
                    <input type="text" name="title" placeholder="Movie Title">
                    <input type="text" name="times" placeholder="Times">



                </fieldset>
                <fieldset>
                    <legend><span class="number">2</span> Attachments </legend>

                    <div class="form-group ">
                      <label> Film Poster <br> </label>

                       <input type="hidden" class="form-control" name="MAX_FILE_SIZE" value="100000000">
                        Upload this Film Poster: <br> <input name="userfile" id="userfile" type="file"> <br>

                        <input type="hidden" class="form-control" name="MAX_FILE_SIZE" value="10000000">
                        Upload this Trailer: <br> <input name="userfile2" id="userfile2" value="10000000" type="file"> <br>                    


                        </div>                  


                </fieldset>
                    <input type="submit" name = "submit" value="Upload" />
            </form>
            </div>              

</body> 

</html>

0 个答案:

没有答案