Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli_stmt::bind_param():类型定义字符串中的元素数不为';与绑定变量的数量不匹配,无法更新_Php_Html - Fatal编程技术网

Php mysqli_stmt::bind_param():类型定义字符串中的元素数不为';与绑定变量的数量不匹配,无法更新

Php mysqli_stmt::bind_param():类型定义字符串中的元素数不为';与绑定变量的数量不匹配,无法更新,php,html,Php,Html,我在提交或更新此数据时遇到问题。数据无法更新 此代码: if(isset($_GET['newsid'])){ if(isset($_POST['submit'])){ $sql = $connect->prepare("UPDATE news set title =?, short_desc =?, isi =?, author =?, status =?, date_period_start =?, date_period_end =?, category

我在提交或更新此数据时遇到问题。数据无法更新

此代码:

if(isset($_GET['newsid'])){
    if(isset($_POST['submit'])){
        $sql = $connect->prepare("UPDATE news  set title =?, short_desc =?, isi =?, author =?, status =?,  date_period_start =?,  date_period_end =?, category =? WHERE newsid =?");
        $sql->bind_param('aaaaa', 
          $title,$short_desc,$isi,$author,$status,
         $date_period_start, $date_period_end, $category);
        $title = $_POST['title'];
        $short_desc = $_POST['short_desc'];
        $isi = $_POST['isi'];
        $author  = $_POST['author'];
        $status = $_POST['status'];
        $date_period_start = $_POST['date_period_start'];
        $date_period_end = $_POST['date_period_end'];
        $category = $_POST['category'];

        if($sql->execute()){
          echo "<script>location.href='index.php'</script>";
        }else{
          echo "<script>alert('".$sql->error."')</script>";
        };
}

$res =$connect->query("SELECT newsid, title, short_desc, isi, author, status, date_period_start, date_period_end, category from news
  where newsid=".$_GET['newsid']);
$row = $res->fetch_assoc();

?>
            <div class="container">
              <div class="row">
                <h2>UPDATE</h2>
              </div>
              <div class="row">


                <form role="form" method="post" action="">
                  <input type="hidden" value="<?php echo $row['newsid'] ?>" name="newid"/>
                  <div class="form-group">
                    <label>Category : </label>
                    <input type="text" name="category" id="category" value="<?php echo $row['category']  ?>"> <br><br>
                  </div>
                  <p>
                   <label> Title : </label>
                   <input name="title" id="title" size="40" maxlength="255" value="<?php echo $row['title']  ?>"/>
                   <p/>
                   <p>
                    <label> Author : </label>
                    <input name="author" id="author" size="40" maxlength="255" value="<?php echo $row['author']  ?>"/>
                    <p/>
                    <br/>
                    <p><label>Short Description : </label> 
                      <textarea  name="short_desc" id="short_desc" value="<?php echo $row['short_desc']  ?>">
                      </textarea>
                    </p>
                    <br>
                    <p>
                      <label>Description: </label>
                      <textarea name="isi" id="isi" rows="7" cols="90" value="<?php echo $row['isi'];  ?>"></textarea>
                    </p>
                    <br/>
                    <p>
                     <label> Status: </label>
                     <input type="text" name="status" id="status" value="<?php echo $row['status']  ?>"/> <br><br>
                     <p/>
                     <p>
                      <label> Display Periode </label>

                      <input type="text" id="date_period_start" name="date_period_start" value="<?php echo $row['date_period_start']  ?>"/>
                      <input type="text" id="date_period_end" name="date_period_end" value="<?php echo $row['date_period_end']  ?>"/>
                      <input type="checkbox" name="cek" value="yes"/><br><br>
                    </p> 

                    <button type="submit" name="submit" class="btn btn-default">Submit</button>
                  </form>
          <?php
        }
          ?>
并发出此警报:
没有为准备好的语句中的参数提供数据。

事实上,我无法更新数据

请帮我解这个代码。我更新时找不到任何错误


谢谢。

正在查看您的SQL更新语句

UPDATE news  set title =?, short_desc =?, isi =?, author =?, status =?, category =? WHERE newsid =?
我能数到7个参数。当我看到你的
bind_参数
调用

$sql->bind_param('aaaaa', 
     $title,$short_desc,$isi,$author,$status,
     $date_period_start, $date_period_end, $category);

我计算了5个类型字符(
'aaaaaa'
)和8个参数(
$title、$short\u desc、$isi、$author、$status、$date\u period\u start、$date\u period\u end、$category
)。这些都需要匹配。阅读可能会有所帮助。

绑定参数中的aaaa无效,它需要是s表示字符串,i表示整数,d表示双精度。

是的,我已经在8参数中更改了它。但仍然不起作用。非常感谢。
$sql->bind_param('aaaaa', 
     $title,$short_desc,$isi,$author,$status,
     $date_period_start, $date_period_end, $category);