Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
DATA NOT SAVE INTO MY SQL DATABASE AFTER CLICK SUBMIT BUTTON ERROR "Confirm form resubmission
The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?




<?php
session_start();
error_reporting(0);
include('includes/dbconnection.php');
if (strlen($_SESSION['crmsuid']==0)) {
  header('location:logout.php');
  } else{
      if(isset($_POST['submit']))
  {

$uid=$_SESSION['crmsuid'];
 $polsta=$_POST['PoliceStationName'];
$pdata=explode(",",$polsta);
$psid=$pdata[0];
$psname=$pdata[1];
$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'];
$SitrepID=mt_rand(100000000, 999999999);
 
$sql="insert into sitrep(SitrepID,UserID,PoliceStationId,PoliceStationName,CategoryName,FirNo,Cdate,UnderSection,appname,Parentage,Contact,Address,ArrestDetails,SeizureDetails,IoName,ContactIo,Gist)values(:SitrepID,:uid,:psid,:polsta,:CategoryName,:FirNo,:Cdate,:UnderSection,:appname,:Parentage,:Contact,:Address,:ArrestDetails,:SeizureDetails,:IoName,:ContactIo,:Gist)";
$query=$dbh->prepare($sql);

$query->bindParam(':SitrepID',$SitrepID,PDO::PARAM_STR);
$query->bindParam(':uid',$uid,PDO::PARAM_STR);
$query->bindParam(':psid',$psid,PDO::PARAM_STR);
$query->bindParam(':polsta',$PoliceStationName,PDO::PARAM_STR);
$query->bindParam(':CategoryName',$CategoryName,PDO::PARAM_STR);
$query->bindParam(':FirNo',$FirNo,PDO::PARAM_STR);
$query->bindParam(':cdate',$cdate,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("Police Station detail has been added.")</script>';
echo "<script>window.location.href ='add-Sitrep.php'</script>";
 }else{
         echo '<script>alert("Something Went Wrong. Please try again")</script>';
         echo "<script>window.location.href ='add-sitrep.php'</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>Sitrep 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>Sitrep 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">Sitrep 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 } ?>


What I have tried:

DATA NOT SAVE INTO MY SQL DATABASE AFTER CLICK SUBMIT BUTTON ERROR "Confirm form resubmission <pre>The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?
Posted
Updated 9-Apr-23 4:18am

1 solution

I don't do PHP because I enjoy what little sanity I have left, but one glaring problem is you are using a random number as a record key. That's not going to work and WILL cause you problems. An id number for a record should be generated by the database, not your code.

Attempting to use a random number WILL generate the same number for more than one record, essentially destroying your data integrity.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900