PHP & SQL-Query is not being read

Asked

Viewed 28 times

0

I have the following code, something is happening but I can’t understand why. I mean the query is not being read, echo appears immediately saying "error"

<?php
        $_SESSION['message'] ='';
        include("config.php");

    if($_SERVER['REQUEST_METHOD'] == 'POST') {

         if(isset($_POST["send"])){

            $ISBN =$conn->real_escape_string($_POST['ISBN']);
            $Authorsname=$conn ->real_escape_string($_POST['Authorsname']);
            $Title= $conn ->real_escape_string($_POST['Title']);
            $edition= $conn ->real_escape_string($_POST['edition']);
            $year= $conn->real_escape_string($_POST['year']);
            $publisher= $conn->real_escape_string($_POST['publisher']);
            $category=$conn->real_escape_string($_POST['category']);
            $quantityinstock=$conn->real_escape_string($_POST['quantityinstock']);
            $price= $conn->real_escape_string($_POST['price']);


         }
               $stmt = $conn->prepare("UPDATE books SET Authorsname =?, Title=?, edition=?, year=?, category=?, publisher=?, quantityinstock=?, price=? WHERE ISBN=?");
               $stmt->bind_param("sssiissii",$ISBN,$Authorsname,$Title,$edition,$year,$publisher,$category,$quantityinstock,$price);
               $ISBN = $_POST['ISBN'];
               $Authorsname = $_POST['Authorsname'];
               $Title = $_POST['Title'];
               $edition = intval($_POST['edition']);
               $year = intval($_POST['year']);
               $publisher = $_POST['publisher'];
               $category = $_POST['category'];
               $quantityinstock = intval($_POST['quantityinstock']);
               $price = intval($_POST['price']);
               $stmt->execute();
               $stmt->store_result();


         if($stmt->affected_rows > 0)
         {
            $message = "You have succefully updated";
                    echo "<script>alert('$message'); window.location.href='update.php';</script>";


            }
                else
                {
                    echo 'Error';

                }
            }

    ?>
  • Foul after SET corresponding to $ISBN

1 answer

0


Has reversal

$stmt = $conn->prepare( ....... , category=?, publisher=?,  
$stmt->bind_param( ...............$publisher,$category,

and missing after ...UPDATE books SET the name of the column to be updated with the value corresponding to $ISBN variable

$stmt = $conn->prepare("UPDATE books SET ISBN =?, Authorsname =?,

$stmt->bind_param("sssiissii",$ISBN,$Authorsname,
  • really this may be one of the mistakes, I followed your suggestion but nevertheless continues to give Error

  • ISBN is at the end of the query where it says WHERE ISBN=?

  • I don’t understand this update of this code, but in any other update I know that to set 9 columns it is necessary to pass 9 values, one for each column and the WHERE clause returns only the values of the rows that meet the specified conditions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.