我相信查询中有关如何将信息插入数据库以进行更新的错误



该程序应该使用表单来更新数据库

我删除了更新表的查询,然后页面出现,我有一个预设检查器,该检查器检查是否发布了ID/ISBN参数,将我重定向到错误页面,当我将查询提出查询以进行更新时页面显示,当我添加时,我将重定向到页面

这是我认为具有错误

的代码
$sql = "UPDATE books SET ISBN=?,Title=?,PubDate=?,PubID=?,Cost = ?, Retail = ?, Category = ? WHERE books.ISBN='$isbn'";
  if($stmt = $mysqli->prepare($sql)){
        $stmt->bind_param("issiiis", $isbn, $title,$pubdate,$pubid,$cost,$retail,$category);
            
            // Set parameters
            $ISBN = $isbn;
            $Title = $title;
            $PubDate = $pubdate;
            $PubID = $pubid;
            $Cost = $cost;
            $Retail = $retail; 
            $Category = $category;
            
            
            // Attempt to execute the prepared statement
            if($stmt->execute())
            {
                echo "starting query";
                // Records created successfully. Redirect to landing page
                
                  header("location: index.php");
                exit();
            } else
            {
                echo $stmt->error; //"Something went wrong. Please try again later.";
            }
        
            
        }
        // Close statement  
        $stmt->close(); 
    }

另一个不是从数据库获取信息的查询

    // Check existence of student_ID parameter before processing further
    if(isset($_GET["ISBN"]) && !empty(trim($_GET["ISBN"])))
    {
        // Get URL parameter
        $id =  trim($_GET["ISBN"]);
               
        // Prepare a select statement
        $sql = "SELECT * FROM books WHERE ISBN = ?";
        
        if($stmt = $mysqli->prepare($sql)){
            // Bind variables to the prepared statement as parameters
            $stmt->bind_param("s", $param_id);
            
            // Set parameters
            $param_id = $isbn;
            
            // Attempt to execute the prepared statement
            if($stmt->execute()){
                $result = $stmt->get_result();
                
                if($result->num_rows == 1){
                    /* Fetch result row as an associative array. Since the result set
                    contains only one row, we don't need to use while loop */
                    $row = $result->fetch_array(MYSQLI_ASSOC);
                    
                    // Retrieve individual field value
                    $ISBN = $row["ISBN"];
                    $Title= $row["Title"];
                    $PubDate = $row["PubDate"];
                    $PubID = $row["PubID"];
                    $Cost = $row["Cost"];
                    $Retail = $row["Retail"];
                    $Category = $row["Category"];
                    
                }
                else
                {
                    // URL doesn't contain valid student_ID. Redirect to error page
                    header("location: error.php");
                    exit();
                }
                
            }
            else
            {
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
        
        // Close statement
        $stmt->close();
        
        // Close connection
        $mysqli->close();
    }  else{
        // URL doesn't contain student_ID parameter. Redirect to error page
        header("location: error.php");
        exit();
} 

我对代码的数量和无知表示歉意,但这非常重要

您的类型字符串是否正确?

您正在通过" Issiiis",因此ISBN被作为整数传递。在Where子句中,尽管您将其视为字符串,它似乎更有可能给定破折号和可能的领先零?

最新更新