【解決方法】致命的なエラー: キャッチされていない pdoexception: SQLSTATE[HY093]:

[ad_1]

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\crimerms\user\add-sitrep.php:45 Stack trace: #0 C:\xampp\htdocs\crimerms\user\add-sitrep.php(45): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\crimerms\user\add-sitrep.php on line 45

私が試したこと:

<?php
session_start();
//error_reporting(0);
include('includes/dbconnection.php');
if (strlen($_SESSION['crmsuid']==0)) {
  header('location:logout.php');
  } else{
      if(isset($_POST['submit']))
  {
$PoliceStationName=$_POST['PoliceStationName'];
$CategoryName=$_POST['CategoryName'];
$FirNo=$_POST['FirNo'];
$Cdate=$_POST['Cdate']; 
$UnderSection=$_POST['UnderSection'];
$appname=$_POST['appname'];
$Parentage=$_POST['Parentage'];
$Contact=$_POST['Contact'];
$Address=$_POST['Address'];
$ArrestDetails=$_POST['ArrestDetails'];
$SeizureDetails=$_POST['SeizureDetails'];
$IoName=$_POST['IoName'];
$ContactIo=$_POST['ContactIo'];
$Gist=$_POST['Gist'];

 
 
$sql="insert into sitrep(PoliceStationName,CategoryName,FirNo,Cdate,UnderSection,appname,Parentage,Contact,Address,ArrestDetails,SeizureDetails,IoName,ContactIo,Gist)values(:PoliceStationName,:CategoryName,:FirNo,:Cdate,:UnderSection,:appname,:Parentage,:Contact,:Address,:ArrestDetails,:SeizureDetails,:IoName,:ContactIo,:Gist)";
$query=$dbh->prepare($sql);


$query->bindParam(':PoliceStationName',$PoliceStationName,PDO::PARAM_STR);
$query->bindParam(':FirNo',$FirNo,PDO::PARAM_STR);
$query->bindParam(':cdate',$cdate,PDO::PARAM_STR);
$query->bindParam(':ctime',$ctime,PDO::PARAM_STR);
$query->bindParam(':UnderSection',$UnderSection,PDO::PARAM_STR);
$query->bindParam(':appname',$appname,PDO::PARAM_STR);
$query->bindParam(':Parentage',$Parentage,PDO::PARAM_STR);
$query->bindParam(':Contact',$Contact,PDO::PARAM_STR);
$query->bindParam(':Address',$Address,PDO::PARAM_STR);
$query->bindParam(':ArrestDetails',$ArrestDetails,PDO::PARAM_STR);
$query->bindParam(':SeizureDetails',$SeizureDetails,PDO::PARAM_STR);
$query->bindParam(':ContactIo',$ContactIo,PDO::PARAM_STR);
$query->bindParam(':Gist',$Gist,PDO::PARAM_STR);

 $query->execute();
   $LastInsertId=$dbh->lastInsertId();
   if ($LastInsertId>0) {
    echo '<script>alert("Criminal Record Has Been Save.")</script>';
echo "<script>window.location.href ='add-sitrep.php'</script>";
  }
  else
    {
         echo '<script>alert("Something Went Wrong. Please try again")</script>';
    }

}}
?>
<!doctype html>
<html class="fixed">
	<head>
		<title>Crime Record Management System | FIR Form</title>
		
		<!-- Web Fonts  -->
		<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css">

		<!-- Vendor CSS -->
		<link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.css" />
		<link rel="stylesheet" href="../assets/vendor/font-awesome/css/font-awesome.css" />
		<link rel="stylesheet" href="../assets/vendor/magnific-popup/magnific-popup.css" />
		<link rel="stylesheet" href="../assets/vendor/bootstrap-datepicker/css/datepicker3.css" />
		<link rel="stylesheet" href="../assets/stylesheets/theme.css" />
		<link rel="stylesheet" href="../assets/stylesheets/skins/default.css" />
		<link rel="stylesheet" href="../assets/stylesheets/theme-custom.css">
		<script src="../assets/vendor/modernizr/modernizr.js"></script>

	</head>
	<body>
		<section class="body">

			<!-- start: header -->
		<?php include_once('includes/header.php');?>
			<!-- end: header -->

			<div class="inner-wrapper">
				<!-- start: sidebar -->
				<?php include_once('includes/sidebar.php');?>
				<!-- end: sidebar -->

				<section role="main" class="content-body">
					<header class="page-header">
						<h2>FIR Form</h2>
					
						<div class="right-wrapper pull-right">
							<ol class="breadcrumbs">
								<li>
									<a href="dashboard.php">
										class="fa fa-home">
									</a>
								</li>
								<li><span>Add</span></li>
								<li><span>FIR Form</span></li>
							</ol>
					
							<a class="sidebar-right-toggle" data-open="sidebar-right">^__i class="fa fa-chevron-left"></a>
						</div>
					</header>

					<!-- start: page -->
					
					<div class="row">
						<div class="col-md-12">
							<form class="form-horizontal" method="post">
								 
								<section class="panel">
									<header class="panel-heading">
										<h2 class="panel-title">FIR Form</h2>
									
									</header>
									<div class="panel-body">
										<div class="validation-message">
											<ul></ul>
										</div>
										
<div class="form-group">
											<label class="col-sm-3 control-label">Police Station *</label>
											<div class="col-sm-9">
												<select type="text" class="form-control" name="PoliceStationName" value="" required="true">
													<option value="">Select Police Station</option>
							 	<?php 

$sql2 = "SELECT * from   tblpolicestation";
$query2 = $dbh -> prepare($sql2);
$query2->execute();
$result2=$query2->fetchAll(PDO::FETCH_OBJ);

foreach($result2 as $row)
{          
    ?>  
<option value="<?php echo htmlentities($row->id.','.$row->PoliceStationName);?>"><?php echo htmlentities($row->PoliceStationName);?>-(<?php echo htmlentities($row->PoliceStationCode);?>)</option>
 <?php } ?>
			

 												</select>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Crime Type *</label>
											<div class="col-sm-9">
												<select type="text" class="form-control" name="CategoryName" value="" required='true'>
													<option value="">Choose Crime Type</option>
							 	<?php 

$sql2 = "SELECT * from   tblcategory";
$query2 = $dbh -> prepare($sql2);
$query2->execute();
$result2=$query2->fetchAll(PDO::FETCH_OBJ);

foreach($result2 as $row)
{          
    ?>  
<option value="<?php echo htmlentities($row->CategoryName);?>"><?php echo htmlentities($row->CategoryName);?></option>
 <?php } ?>
												</select>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">FIR Number *</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="FirNo" value="" required='true'>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Case Number *</label>
											<div class="col-sm-9">
												<input type="date" class="form-control" name="Cdate" value="" required='true'>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Under Section *</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="UnderSection" value="" required='true'>
											</div>
										</div>
										
															
																													
										<p style="font-size: 18px;color: red;padding-left: 10px"> Applicant's Detail(Victim)</p>
										<div class="form-group">
											<label class="col-sm-3 control-label">Name *</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="appname" value="" required='true'>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label">Parentage *</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="Parentage" value="" required='true'>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label">Contact Number *</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="Contact" value="" required='true' maxlength="10" pattern="[0-9]+">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label">Address*</label>
											<div class="col-sm-9">
												<textarea type="text" class="form-control"  name="Address" value="" required='true'></textarea>
											</div>
										</div>							
										
																			
										
										<p style="font-size: 18px;color: red;padding-left: 10px"> Applicant's Detail(Victim)</p>
										<div class="form-group">
											<label class="col-sm-3 control-label">Arrest Details*</label>
											<div class="col-sm-9">
												<textarea type="text" class="form-control"  name="ArrestDetails" value="" required='true'></textarea>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Seizure Details*</label>
											<div class="col-sm-9">
												<textarea type="text" class="form-control"  name="SeizureDetails" value="" required='true'></textarea>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Name of the IO*</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="IoName" value="" required='true'>
											</div>
										</div>
										
																			<div class="form-group">
											<label class="col-sm-3 control-label">Contact Number*</label>
											<div class="col-sm-9">
												<input type="text" class="form-control" name="ContactIo" value="" required='true' maxlength="10" pattern="[0-9]+">
											</div>
										</div>
										
										
										<div class="form-group">
											<label class="col-sm-3 control-label">Gist of the Case*</label>
											<div class="col-sm-9">
												<textarea type="text" class="form-control"  name="Gist" value="" required='true'></textarea>
											</div>
										</div>							
																			
													
									</div>
									<footer class="panel-footer">
										<div class="row">
											<div class="col-sm-9 col-sm-offset-3">
												<button class="btn btn-sm btn-primary login-submit-cs" type="submit"name="submit">Submit</button>
											</div>
										</div>
									</footer>
								</section>
							</form>
						</div>
					
					</div>
					<!-- end: page -->
				</section>
			</div>

		</section>

		<!-- Vendor -->
		<script src="../assets/vendor/jquery/jquery.js"></script>
		<script src="../assets/vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
		<script src="../assets/vendor/bootstrap/js/bootstrap.js"></script>
		<script src="../assets/vendor/nanoscroller/nanoscroller.js"></script>
		<script src="../assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="../assets/vendor/magnific-popup/magnific-popup.js"></script>
		<script src="../assets/vendor/jquery-placeholder/jquery.placeholder.js"></script>
		<script src="../assets/vendor/jquery-validation/jquery.validate.js"></script>
		<script src="../assets/javascripts/theme.js"></script>
		<script src="../assets/javascripts/theme.custom.js"></script>
		<script src="../assets/javascripts/theme.init.js"></script>
		<script src="../assets/javascripts/forms/examples.validation.js"></script>
	</body>
</html><?php '}' ?>

解決策 1

エラーメッセージを読んでください、それはかなり明確です:

エラー
Invalid parameter number: number of bound variables does not match number of tokens

コードを見てください:

PHP
$sql="insert into sitrep(PoliceStationName,CategoryName,FirNo,Cdate,UnderSection,appname,Parentage,Contact,Address,ArrestDetails,SeizureDetails,IoName,ContactIo,Gist)values(:PoliceStationName,:CategoryName,:FirNo,:Cdate,:UnderSection,:appname,:Parentage,:Contact,:Address,:ArrestDetails,:SeizureDetails,:IoName,:ContactIo,:Gist)";
...
$query->bindParam(':PoliceStationName',$PoliceStationName,PDO::PARAM_STR);
$query->bindParam(':FirNo',$FirNo,PDO::PARAM_STR);
$query->bindParam(':cdate',$cdate,PDO::PARAM_STR);
$query->bindParam(':ctime',$ctime,PDO::PARAM_STR);
$query->bindParam(':UnderSection',$UnderSection,PDO::PARAM_STR);
$query->bindParam(':appname',$appname,PDO::PARAM_STR);
$query->bindParam(':Parentage',$Parentage,PDO::PARAM_STR);
$query->bindParam(':Contact',$Contact,PDO::PARAM_STR);
$query->bindParam(':Address',$Address,PDO::PARAM_STR);
$query->bindParam(':ArrestDetails',$ArrestDetails,PDO::PARAM_STR);
$query->bindParam(':SeizureDetails',$SeizureDetails,PDO::PARAM_STR);
$query->bindParam(':ContactIo',$ContactIo,PDO::PARAM_STR);
$query->bindParam(':Gist',$Gist,PDO::PARAM_STR);

次に、列 laves を値と比較し、実際のパラメーターを準備します。

コラム
Column Name         Value               Parameter                
PoliceStationName   :PoliceStationName  :PoliceStationName
CategoryName        :CategoryName       :FirNo            
FirNo               :FirNo              :cdate                
Cdate               :Cdate              :ctime                
UnderSection        :UnderSection       :UnderSection         
appname             :appname            :appname              
Parentage           :Parentage          :Parentage            
Contact             :Contact            :Contact              
Address             :Address            :Address              
ArrestDetails       :ArrestDetails      :ArrestDetails        
SeizureDetails      :SeizureDetails     :SeizureDetails       
IoName              :IoName             :ContactIo            
ContactIo           :ContactIo          :Gist                 
Gist                :Gist                   

「IoName」パラメータはどこにありますか?

[ad_2]

コメント

タイトルとURLをコピーしました