0

Hi for some reason my update statement is not working, most probably because of the id=%d, its not getting the id for the statement i think but its finding the id because it is listed in the url (shown Below). What is the problem please ?

This works when i Insert a number for the id, example : id=77, so most probably the problem is the %d how can i get it to find the id with the %d ?

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>
Julian Zahra
  • 63
  • 1
  • 9

0 Answers0