问题描述
提交或更新此数据时出现问题.数据无法更新.
I have a problem when i submit or update this data. The data cannot update.
此代码:
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
}
?>
我得到的输出:
mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables .
还要发出此警报:no data supplied for parameters in prepared statement.
实际上,我无法更新数据.
And actually, i cannot Update the data.
请帮助我解决此代码.更新时找不到任何错误
Please help me to solve this code. I can't find any error when i update
谢谢.
推荐答案
查看您的SQL Update语句
Looking at your SQL Update statement
UPDATE news set title =?, short_desc =?, isi =?, author =?, status =?, category =? WHERE newsid =?
我可以计算7个参数.当我看着您的bind_param
电话
I can count 7 parameters. When I look at your bind_param
call
$sql->bind_param('aaaaa',
$title,$short_desc,$isi,$author,$status,
$date_period_start, $date_period_end, $category);
我计算了5个键入字符('aaaaa'
)和8个参数($title, $short_desc, $isi, $author, $status, $date_period_start, $date_period_end, $category
).这些 all 需要匹配.读这可能会有所帮助.
I count 5 type characters ('aaaaa'
) and 8 parameters ($title, $short_desc, $isi, $author, $status, $date_period_start, $date_period_end, $category
). These all need to match. Reading this might help.
这篇关于mysqli_stmt :: bind_param():类型定义字符串中的元素数量与绑定变量的数量不匹配,并且无法更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!