我这里有更新的代码,我的问题是我得到了这种错误" SQLSTATE [HY093]:参数号无效:绑定变量的数量与令牌的数量不匹配"而且我不知道如何解决这个问题。有人可以帮我解决这个问题吗?
class.user.php
public function update($user_id,$username,$password,$province)
{
try
{
$stmt=$this->db->prepare("UPDATE login SET username=:username,password=:password,province=:province WHERE user_id=:user_id");
$stmt->bindparam(":username",$username);
$stmt->bindparam(":password",$password);
$stmt->bindparam(":province",$province);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
,这是update.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_POST['btn-update']))
{
$user_id = $_GET['user_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$province = $_POST['province'];
if($crud->update($user_id,$username,$password,$province))
{
echo "<script type='text/javascript'>alert('Successfully Updated!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!');</script>";
}
}
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<div id="Survey-Update">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>Date Reported</td>
<td>
<input name="username" class="form-control" type="text" value="<?php echo $username; ?>">
</td>
<td>Remarks</td>
<td>
<textarea id="Remarks" type="text" name="password" class="form-control" value="<?php echo $password; ?>">
</textarea>
</td>
</tr>
<tr>
<td>Remarks</td>
<td>
<textarea id="Remarks" type="text" name="province" class="form-control" value="<?php echo $province; ?>">
</textarea>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="edit"></span>Update</button>
<a href="insert.php" onClick="self.close()"> CANCEL</a>
</td>
</tr>
</table>
</form>
</div>
答案 0 :(得分:0)
错误表示 <form class="form-inline" role="form" id="frmadd" action="<?php echo base_url() ?>index.php/staff_controller/create" method="POST">
<div class="form-group">
<label class="sr-only" for="first_name">First name</label>
<input type="text" name="first_name" class="form-control" id="first_name" placeholder="First Name">
</div>
<div class="form-group">
<label class="sr-only" for="last_name">Last name</label>
<input type="text" name="last_name" class="form-control" id="first_name" placeholder="Last Name">
</div>
<div class="form-group">
<label class="sr-only" for="title">Title</label>
<?php
$attributes = 'class = "form-control" id = "designation"';
echo form_dropdown('designation',$designation, set_value('designation'), $attributes);?>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">@</div>
<input class="form-control" name="email" type="email" placeholder="Enter email">
</div>
<div class="form-group">
<label class="sr-only" for="address">Address</label>
<input type="text" name="address" class="form-control" id="address" placeholder="address">
</div>
<div class="form-group">
<label class="sr-only" for="contact_no">Contact</label>
<input type="text" class="form-control" name="contact_no" id="contact_no" placeholder="contact number">
</div>
<div class="form-group">
<label class="sr-only" for="work_experience">Work Experience</label>
<input type="text" class="form-control" name="work_experience" id="work_experience" placeholder="Work Experience">
</div>
<div class="form-group">
<label class="sr-only" for="qualifications">Qualifications</label>
<input type="text" class="form-control" name="qualifications" id="qualifications" placeholder="Qualifications">
</div>
<div class="form-group">
<label class="sr-only" for="nic">NIC</label>
<input type="text" class="form-control" name="nic" id="nic" placeholder="NIC">
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" id="btn btn-success" value="submit">
</div>
</form>
</div>
<table class="table">
<thead><tr><th>First Name</th><th>Last Name</th><th>Title</th><th>Email</th><th>Address</th><th>Contact</th><th>Work Experience</th><th>Qualifications</th><th>created</th><th>Action</th></tr></thead>
<tbody id="fillgrid">
</tbody>
<tfoot></tfoot>
</table>
的数量与bindparams
的数量不同。您有4个参数,但只能绑定3个。
你有:
parameters
你应该有类似的东西:
$stmt=$this->db->prepare("UPDATE login SET username=:username,password=:password,province=:province WHERE user_id=:user_id");
$stmt->bindparam(":username",$username);
$stmt->bindparam(":password",$password);
$stmt->bindparam(":province",$province);
您永远不会绑定$stmt=$this->db->prepare("UPDATE login SET username=:username,password=:password,province=:province WHERE user_id=:user_id");
$stmt->bindparam(":username",$username);
$stmt->bindparam(":password",$password);
$stmt->bindparam(":province",$province);
$stmt->bindparam(":user_id",$user_id);
参数。