show your code view controller
Nov 2, 2022
14
Level 1
the page won't show inserted data, after refresh it become doubled
here is the code
<?php
include('inc/head.php');
session_start();
if (isset($_SESSION['email']))
{
}
else
{
header('location:index.php');
}
?>
<body>
<nav class="navbar navbar-toggleable-sm navbar-inverse bg-inverse p-0">
<div class="container">
<button class="navbar-toggler toggler-right" data-target="#mynavbar" data-toggle="collapse">
<span class="navbar-toggler-icon"></span>
</button>
<a href="#" class="navbar-brand mr-3">Online Move In Items</a>
<div class="collapse navbar-collapse" id="mynavbar">
<ul class="navbar-nav">
<li class="nav-item px-2"><a href="#" class="nav-link active">Logged in as <?php echo $_SESSION['email']?></a></li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown mr-3">
<li class="nav-item">
<a href="logout.php" class="nav-link"><i class="fa fa-power-off"> </i>Log Out</a>
</li>
</li>
</ul>
</div>
</div>
</nav>
<!--This Is Header-->
<header id="main-header" class="bg-primary py-2 text-white">
<div class="container">
<div class="row">
<div class="col-md-6">
<h1><i class="fa fa-tachometer"> </i>Dashboard</h1>
</div>
</div>
</div>
</header>
<!--This is section-->
<section id="sections" class="py-4 mb-4 bg-faded">
<div class="container">
<div class="row">
<div class="col-md"></div>
<div class="col-md-3">
<a href="#" class="btn btn-primary btn-block" style="border-radius:0%;" data-toggle="modal" data-target="#addPostModal"><i class="fa fa-plus"> </i>Apply Move In Items</a>
</div>
<div class="col-md-3">
<a href="#" class="btn btn-warning btn-block" style="border-radius:0%;" data-toggle="modal" data-target="#addCateModal"><i class="fa fa-spinner"> </i>Pending Move In Items</a>
</div>
<div class="col-md-3">
<a href="#" class="btn btn-success btn-block" style="border-radius:0%;" data-toggle="modal" data-target="#addUsertModal"><i class="fa fa-check"> </i>Approved Move In Items</a>
</div>
<div class="col-md"></div>
</div>
</div>
</section>
<!----Section2 for showing Post Model ---->
<section id="post">
<div class="container">
<div class="row">
<table class="table table-bordered table-hover table-striped">
<thead>
<th>#</th>
<th>Move In Items Date</th>
<th>ItemList / Amount</th>
<th>Vehicle Type</th>
<th>Vehicle Police Number</th>
<th>Status</th>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM move_in WHERE email='".$_SESSION['email']."'";
$que = mysqli_query($con,$sql);
$cnt=1;
while ($result = mysqli_fetch_array($que)) {
?>
<tr>
<td><?php echo $cnt;?></td>
<td><?php echo $result['moveindate']; ?></td>
<td><?php echo $result['itemlistamount']; ?></td>
<td><?php echo $result['vehicletype']; ?></td>
<td><?php echo $result['vehiclepolicenumber']; ?></td>
<td>
<?php
if ($result['status'] == 0)
{
echo "<span class='badge badge-warning'>Pending</span>";
}
else
{
echo "<span class='badge badge-success'>Approved</span>";
}
$cnt++; }
?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<!----Section3 footer ---->
<section id="main-footer" class="text-center text-white bg-inverse mt-4 p-4">
<div class="container">
<div class="row">
<div class="col">
<p class="lead">© <?php echo date("Y")?> KVM</p>
</div>
</div>
</div>
</section>
<!-- Creating Modal -->
<!-- Header Post -->
<div class="modal fade" id="addPostModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<div class="modal-title">
<h5>Apply Move In Items</h5>
</div>
<button class="close" data-dismiss="modal"><span>×</span></button>
</div>
<div class="modal-body">
<form action="" method="post">
<div class="form-group">
<label class="form-control-label">Move In Items Date* / Items Construction Date** :<p style="color: red;">*only monday-saturday (08.30-17.00)<br>**only monday-friday (08.30-17.00)</p></label>
<input type="date" name="moveindate" class="form-control"/>
</div>
<div class="form-group">
<label>Item Lists / Amount</label><br>
<textarea name="itemlistamount" placeholder="tv 2 refrigerator 1" style="width: 100%;"></textarea>
</div>
<div class="form-group">
<label>Vehicle Type</label>
<input type="text" name="vehicletype" class="form-control"/>
</div>
<div class="form-group">
<label>Vehicle Police Number</label>
<input type="text" name="vehiclepolicenumber" class="form-control"/>
</div>
</div>
<div class="modal-footer">
By clicking apply you are agree to all terms and condition mentioned above
<button class="btn btn-danger" style="border-radius:0%;" data-dismiss="modal">Close</button>
<input type="hidden" name="status" value="0">
<input type="submit" class="btn btn-success" style="border-radius:0%;" name="apply" value="Apply">
</div>
</form>
</div>
</div>
</div>
</div>
<!--Modal Category-->
<div class="modal fade" id="addCateModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-warning text-white">
<div class="modal-title">
<h5>Pending Move In Items</h5>
</div>
<button class="close" data-dismiss="modal"><span>×</span></button>
</div>
<div class="modal-body">
<table class="table table-bordered table-hover table-striped">
<thead>
<th>#</th>
<th>Move In Date</th>
<th>Item List / Amount</th>
<th>Vehicle Type</th>
<th>Vehicle Police Number</th>
<th>Status</th>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM move_in WHERE status = 0 && email='".$_SESSION['email']."'";
$que = mysqli_query($con,$sql);
$cnt=1;
while ($result = mysqli_fetch_array($que)) {
?>
<tr>
<td><?php echo $cnt;?></td>
<td><?php echo $result['moveindate']; ?></td>
<td><?php echo $result['itemlistamount']; ?></td>
<td><?php echo $result['vehicletype']; ?></td>
<td><?php echo $result['vehiclepolicenumber']; ?></td>
<td>
<?php
if ($result['status'] == 0)
{
echo "<span class='badge badge-warning'>Pending</span>";
}
else
{
echo "<span class='badge badge-success'>Approved</span>";
}
$cnt++; }
?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- User Modal -->
<div class="modal fade" id="addUsertModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-success text-white">
<div class="modal-title">
<h5>Approved Move In Items</h5>
</div>
<button class="close" data-dismiss="modal"><span>×</span></button>
</div>
<div class="modal-body">
<table class="table table-bordered table-hover table-striped">
<thead>
<th>#</th>
<th>Move In Date</th>
<th>Item List / Amount</th>
<th>Vehicle Type</th>
<th>Vehicle Police Number</th>
<th>Status</th>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM move_in WHERE status = 1 AND email='".$_SESSION['email']."'";
$que = mysqli_query($con,$sql);
$cnt=1;
while ($result = mysqli_fetch_array($que)) {
?>
<tr>
<td><?php echo $cnt;?></td>
<td><?php echo $result['moveindate']; ?></td>
<td><?php echo $result['itemlistamount']; ?></td>
<td><?php echo $result['vehicletype']; ?></td>
<td><?php echo $result['vehiclepolicenumber']; ?></td>
<td>
<?php
if ($result['status'] == 0)
{
echo "<span class='badge badge-warning'>Pending</span>";
}
else
{
echo "<span class='badge badge-success'>Approved</span>";
}
$cnt++; }
?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/tether.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="https://cdn.ckeditor.com/4.9.1/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor1');
</script>
</body>
</html>
<?php
if (isset($_REQUEST['apply'])){
$email = $_SESSION['email'];
$moveindate = $_REQUEST['moveindate'];
$itemlistamount = $_REQUEST['itemlistamount'];
$vehicletype = $_REQUEST['vehicletype'];
$vehiclepolicenumber = $_REQUEST['vehiclepolicenumber'];
$status = $_REQUEST['status'];
$sql = "INSERT INTO move_in(email,moveindate,itemlistamount,vehicletype,vehiclepolicenumber,status)VALUES('$email','$moveindate','$itemlistamount','$vehicletype','$vehiclepolicenumber','$status')";
$run = mysqli_query($con,$sql);
if($run == true)
{
echo "<script>
alert('Entering Items Requested, Please Wait For 'Approved' Status');
window.open('dashboard.php','_self');
</script>";
}
else
{
echo "<script>
alert('Failed To Apply');
</script>";
}
}
?>
can u tell me what's wrong? i' ve tried fetch_assoc->fetch_array, $_POST->$_REQUEST
Level 22
@JohnCharves
The data doesn't show after insert may be because of insert code is below all other html. Double inserting maybe because you are writing insert code and retrieve code in same page and refreshing run the insert again after pass the if condition.
So you need to make sure insert code is only run after form submit or make a separate file. That is all I can guess.
<?php
if ($_POST['vehicletype'] || $_POST['vehiclepolicenumber'])){
$email = $_SESSION['email'];
$moveindate = $_REQUEST['moveindate'];
$itemlistamount = $_REQUEST['itemlistamount'];
$vehicletype = $_REQUEST['vehicletype'];
$vehiclepolicenumber = $_REQUEST['vehiclepolicenumber'];
//.....
}
?>
//.....
<form action="currentfile.php" method="post">
<div class="form-group">
<label class="form-control-label">Move In Items Date* / Items Construction Date** :<p style="color: red;">*only monday-saturday (08.30-17.00)<br>**only monday-friday (08.30-17.00)</p></label>
<input type="date" name="moveindate" class="form-control"/>
</div>
<div class="form-group">
<label>Item Lists / Amount</label><br>
<textarea name="itemlistamount" placeholder="tv 2 refrigerator 1" style="width: 100%;"></textarea>
</div>
<div class="form-group">
<label>Vehicle Type</label>
<input type="text" name="vehicletype" class="form-control"/>
</div>
<div class="form-group">
<label>Vehicle Police Number</label>
<input type="text" name="vehiclepolicenumber" class="form-control"/>
</div>
</div>
<div class="modal-footer">
By clicking apply you are agree to all terms and condition mentioned above
<button class="btn btn-danger" style="border-radius:0%;" data-dismiss="modal">Close</button>
<input type="hidden" name="status" value="0">
<input type="submit" class="btn btn-success" style="border-radius:0%;" name="apply" value="Apply">
</div>
</form>
//...
?>
1 like
Please or to participate in this conversation.