Here I have to update only category
,sd
,fd
,assignto
,reviewed
by and file upload. So when the user clicks on update button it will go to the update.php
and updates the necessary fields. But its not executing and its showing an a warning:
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
Can somebody tell me what's wrong?
updateview.php
<form action="update.php" method="post" enctype="multipart/form-data" novalidate>
<?php
include_once('dbconn.php');
$srn = $_GET['srn'];
if($stmt = $mysqli->prepare("SELECT srn, client, type, fy, category, sd, fd, assignto, edoc, reviewed, upload FROM main WHERE srn=?")){
$stmt->bind_param("s",$_GET["srn"]);
$stmt->execute();
$stmt->bind_result($srn,$client,$type,$fy,$category,$sd,$fd,$assignto,$edoc,$reviewed,$upload);
$stmt->fetch();
$stmt->close();
}
?>
<label> <span>SRN</span>
<input name="srn" type="text" id="srn" size="15" readonly="readonly" maxlength="40" value="<?php echo $srn; ?>"/>
</label>
<label> <span>Client</span>
<select class="required" name="client" disabled="disabled"/>
<?php
if($stmt = $mysqli->prepare("SELECT cname FROM client")){
$stmt->execute();
$stmt->bind_result($cname);
while($stmt->fetch()){
?>
<option value="<?php echo $cname; ?>" <?php if($cname==$client){ echo "selected"; } ?>> <?php echo $cname; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT OF CLIENT */
?>
</select>
<input type="hidden" name="client" value = "<?php echo $row['client']; ?>" />
</label>
<label> <span>Type</span>
<select class="required" name="type" disabled="disabled"/>
<?php
if($stmt = $mysqli->prepare("SELECT type FROM entity")){
$stmt->execute();
$stmt->bind_result($type);
while($stmt->fetch()){
?>
<option value="<?php echo $type; ?>" <?php if($type==$type){ echo "selected"; } ?>> <?php echo $type; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT */
?>
</select>
<input type="hidden" name="type" value = "<?php echo $row['type']; ?>" />
</label>
<label> <span>Financial Year</span>
<select class="required" name="fy" disabled="disabled"/>
<?php
if($stmt = $mysqli->prepare("SELECT year FROM fy")){
$stmt->execute();
$stmt->bind_result($year);
while($stmt->fetch()){
?>
<option value="<?php echo $year; ?>" <?php if($year==$fy){ echo "selected"; } ?>> <?php echo $year; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT OF */
?>
</select>
<input type="hidden" name="fy" value = "<?php echo $row['fy']; ?>" />
</label>
<label> <span>Category</span>
<select class="required" name="category"/>
<?php
if($stmt = $mysqli->prepare("SELECT name FROM category")){
$stmt->execute();
$stmt->bind_result($name);
while($stmt->fetch()){
?>
<option value="<?php echo $name; ?>" <?php if($name==$category){ echo "selected"; } ?>> <?php echo $name; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT OF CATEGORY */
?>
</select>
</label>
<label> <span>Short Description</span>
<textarea required="required" name='sd'><?php echo $sd; ?></textarea>
</label>
<label> <span>Full Description</span>
<textarea required="required" name='fd'><?php echo $fd; ?></textarea>
</label>
<label> <span>Assign To</span>
<select class="required" name="assignto"/>
<?php
if($stmt = $mysqli->prepare("SELECT name FROM assignto")){
$stmt->execute();
$stmt->bind_result($name);
while($stmt->fetch()){
?>
<option value="<?php echo $name; ?>" <?php if($name==$name){ echo "selected"; } ?>> <?php echo $name; ?> </option>
<?php
}
$stmt->close();
}
?>
</select>
</label>
<label> <span>EDOC</span>
<input name="edoc" type="text" id="edoc" size="15" readonly="readonly" maxlength="40" value="<?php echo $edoc; ?>"/>
</label>
<label> <span>Reviewed By</span>
<select class="required" name="reviewed"/>
<?php
if($stmt = $mysqli->prepare("SELECT type FROM entity")){
$stmt->execute();
$stmt->bind_result($type);
while($stmt->fetch()){
?>
<option value="<?php echo $type; ?>" <?php if($type==$reviewed){ echo "selected"; } ?>> <?php echo $type; ?> </option>
<?php
}
$stmt->close();
}
?>
</select>
</label>
<label>
<span>Input Attachment</span>
<input type="file" name ="filename" required>
</label>
<button id='cancel' type='cancel'>Cancel</button>
<button id='send' type='submit'>Update</button>
</form>
update.php
<?php
include('dbconn.php');
$srn = $_POST['srn'];
$client = $_POST['client'];
$type = $_POST['type'];
$fy = $_POST['fy'];
$category = $_POST['category'];
$sd = $_POST['sd'];
$fd = $_POST['fd'];
$assignto = $_POST['assignto'];
$edoc = $_POST['edoc'];
$reviewed = $_POST['reviewed'];
$stmt = $mysqli->prepare("UPDATE main SET category=?,sd=?,fd=?,assignto=?,reviewed=?,upload=? WHERE srn=?");
$stmt->bind_param('sssssb',$srn,$category, $sd,$fd,$assignto,$reviewed,$upload);
$stmt->execute();
?>
dbconn.php
<?php
$host = "localhost";
$user = "root";
$pwd = "root";
$db = "eservice";
$mysqli = new mysqli($host,$user,$pwd,$db);
/* ESTABLISH CONNECTION */
if (mysqli_connect_errno()) {
echo "Failed to connect to mysql : " . mysqli_connect_error();
exit();
}
?>