How to prevent the image from being flipped? - php

When i charge the image this sees flipped but is only with some ones, and all was uploaded with the dropzone, I have a form that serves only to upload the image by dragging, only one photo is allowed to be uploaded since it is used for the profile picture of each birthday boy, then the photo is uploaded and the program is directed to the driver which validates the fields and then create a folder with the id of the user if it does not exist and finally save the image using the user's id as the name and thus replace the previous photo, but with certain photos it is flipped over and the reason is not, and in the database the name of the photo and its extension are stored.
The form that shows the photo is loaded by another driver that loads the photo and the information of the user and then by means of a jquery the view is filled with the information that was obtained.
At this time, you already insert the image and store the name in the database, but when you load it, you see it with a 90 degree turn
<!--View-->
<?php
$link = mysqli_connect("localhost", "pruebas", "xxxx");
mysqli_select_db($link, "colitali_iqpantallas");
$tildes = $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$result = mysqli_query($link, "SELECT * FROM birthdays ORDER BY id");
$estado ="active";
$contador=0;
$delete="";
?>
<div class="alert alert-dismissible" role="alert" style="display: none;">
</div>
<table id="tableBirthdays" class="table display">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Nombre</th>
<th scope="col">Apellido</th>
<th scope="col">Cargo</th>
<th scope="col">Fecha de Nacimiento</th>
<th scope="col">Inicio del cargo</th>
<th scope="col">Imagen</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Cargo</th>
<th>Fecha de Nacimiento</th>
<th>Inicio del cargo</th>
<th>Imagen</th>
</tr>
</tfoot>
<tbody class="contentTable">
<?php
while ($fila = mysqli_fetch_array($result)){
$estado="";
$col_name=$fila['name'];
$col_surname=$fila['surname'];
$col_job=$fila['job'];
$col_id=$fila['id'];
$col_start=$fila['start'];
$col_cumple=$fila['day']."/".$fila['month']."/".$fila['year'];
$col_image=($fila['image']==NULL) ? "default.png" : $col_id."/".$fila['image'] ;
$delete .= '<option class="opcionBirthdays" data-src="birthday" value="'.$col_id.'" title="'.$col_name." ".$col_surname.'">';
$delete .= $col_id.". ";
$delete .= $col_name." ".$col_surname;
$delete .= '</option>';
?>
<tr>
<td>
<label><?php echo $col_id; ?></label>
</td>
<td>
<div class="col">
<div class="row">
<input class="form-control" type="text" name="name" value="<?php echo $col_name; ?>" width="150" id="birthdaysName-<?php echo $col_id; ?>" required/>
<label class="d-none"><?php echo $col_name; ?></label>
</div>
<div class="row">
<button type="button" value="Guardar" name="detail" class="botonIQ btnGuardar" data-action='controller/uploadBirthday.php?tipo=1&code=<?php echo $col_id; ?>'>Guardar</button>
</div>
</div>
</td>
<td>
<div class="col">
<div class="row">
<input class="form-control" type="text" name="surname" value="<?php echo $col_surname; ?>" width="150" id="birthdaysSurname-<?php echo $col_id; ?>" required/>
<label class="d-none"><?php echo $col_surname; ?></label>
</div>
<div class="row">
<button type="button" value="Guardar" name="detail" class="botonIQ btn-xs btnGuardar" data-action='controller/uploadBirthday.php?tipo=2&code=<?php echo $col_id; ?>'>Guardar</button>
</div>
</div>
</td>
<td>
<div class="col">
<div class="row">
<input class="form-control" type="text" name="job" value="<?php echo $col_job; ?>" width="150" id="birthdaysJob-<?php echo $col_id; ?>"required/>
<label class="d-none"><?php echo $col_job; ?></label>
</div>
<div class="row">
<button type="button" value="Guardar" name="detail" class="botonIQ btnGuardar" data-action='controller/uploadBirthday.php?tipo=3&code=<?php echo $col_id; ?>'>Guardar</button>
</div>
</div>
</td>
<td>
<div class="col">
<div class="row">
<input id="birthdaysBirthday-<?php echo $col_id; ?>" class="datepicker form-control" data-elemento="birthdays" width="150" value="<?php echo $col_cumple; ?>" name="birthday" readonly required/>
<label class="d-none"><?php echo $col_cumple; ?></label>
</div>
<div class="row">
<button type="button" value="Guardar" name="detail" class="botonIQ btn-xs btnGuardar" data-action='controller/uploadBirthday.php?tipo=4&code=<?php echo $col_id; ?>'>Guardar</button>
</div>
</div>
</td>
<td>
<div class="col">
<div class="row">
<input id="birthdaysStart-<?php echo $col_id; ?>" class="datepicker form-control" data-elemento="birthdays" width="150" value="<?php echo $col_start; ?>" name="start" readonly required/>
<label class="d-none"><?php echo $col_start; ?></label>
</div>
<div class="row">
<button type="button" value="Guardar" name="detail" class="botonIQ btnGuardar" data-action='controller/uploadBirthday.php?tipo=5&code=<?php echo $col_id; ?>'>Guardar</button>
</div>
</div>
</td>
<td>
<form action='controller/uploadBirthday.php?tipo=6&code=<?php echo $col_id; ?>' class='dropzone' data-elemento="birthdays" enctype='multipart/form-data' id='birthdaysImage-<?php echo $col_id; ?>' style="height: 150px; width: 100px; font-size: 10px">
<img class='img-l miniImagen' width="40px" height="40px" src='images/<?php echo $col_image; ?>' />
</form>
</td>
</tr>
<?php
$contador++;
}
?>
<!-- Controller -->
<?php
include_once "con.php";
switch ($_GET['tipo']) {
case 1:
//Modificar el nombre //error
break;
case 2:
//Modificar el apellido
break;
case 3:
//Modificar el cargo
break;
case 4:
//Modificar la fecha de nacimiento
break;
case 5:
//Modificar la fecha en la que empezo a trabjar
break;
case 6:
//Modificar la imagen
if (isset($_GET['code'])) {
$id=$_GET['code'];
if (!file_exists('../images/'.$id)) {
$oldmask = umask(0);
mkdir('../images/'.$id, 0777);
umask($oldmask);
}
if($fila['image']!=NULL) {
unlink('../images/'.$id."/".$id.'.png');
}
$ds = DIRECTORY_SEPARATOR;
$storeFolder = '../images/'.$id;
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath.$id. ".png";
move_uploaded_file($tempFile,$targetFile);
$con->query("SET NAMES 'utf8'");
$sentencia = $con->prepare("UPDATE birthdays SET image = ? WHERE id = ?;");
$resultado = $sentencia->execute([$id.'.png', $id]);
}
else {
die("No se a subido nada");
}
}
else {
die("No se a recibido nada");
}
break;
}
include_once "bitacora.php";
header('Location: ../home.php?forms=birthdays');
?> ```
The image should look right, that is to say as it was taken with the cell phone or the camera, but it is seen flipped
[!look the this image, this is the visual of the problem][1]][1]
[1]: https://i.stack.imgur.com/zMg6A.png

Related

How to get/pass the value to modal

How can I pass the value of order_id from order.php to ordermodal.php, So I can use it in my query.
This is the order.php
UI of order.php
<?php
session_start();
$order_id = $_SESSION['order_id'];
if (!isset($_SESSION['user_id']))
{
header("Location: index.php");
}
$_SESSION['navMenu'] = "order";
ini_set('display_errors', 'On');
require_once 'includes/database.php';
include_once 'system_menu.php';
include_once 'ordermodal.php';
$sql2 = "SELECT * FROM cart_tbl";
$sql = "SELECT * FROM order_tbl WHERE order_status = 'Accepted' or order_status = 'Dispatched' or order_status = 'Pending' ORDER BY order_datetime DESC";
/*** * SET UP COMBO BOX FOR SEARCH */
$comboBox = isset($_REQUEST['comboBoxVal']) ? trim($_REQUEST['comboBoxVal']) : '';
$search_by = isset($_REQUEST['search_by']) ? addslashes($_REQUEST['search_by']) : 0;
$users = null;
if ($comboBox != '') { switch ($search_by) {
case 1://Order ID
$sql .= " WHERE order_id LIKE '%{$comboBox}%' ";
break;
}
}
$carts = mysqli_query(connection(), $sql2);
$orders = mysqli_query(connection(), $sql);
$search_filters = array(1 => 'Order ID');
/*** * END SET UP COMBO BOX */ ?>
<html>
<head>
<title>ORDERS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
background:url(images/jerica.jpg)fixed no-repeat center;
background-size:cover;
}
.asd {
color: white;
}
</style>
</head>
<body>
<?php
if (isset($_SESSION['message'])) {
$message = $_SESSION['message']; unset($_SESSION['message']);
}
else {
$message = "";
}
?> <div class="container" >
<h1 class="asd">Orders</h1>
</div> <div class="container" >
<div class="panel panel-default" >
<div class="panel-heading"> <form method="post"> <div class="input-group">
<div class="input-group-addon"> <select name="search_by">
<?php
foreach ($search_filters as $key => $value): ?>
<option value="<?= $key ?>" <?= $key == $search_by ? 'selected' : '' ?> > <?= $value ?> </option>
<?php
endforeach;
?>
</select>
</div>
<input type="search" name="comboBoxVal" value="<?= $comboBox ?>" class="form-control" placeholder="Search">
</div>
</form>
</div>
<div class="panel-body">
<?php
if ($message != ''): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true"> ×</span></button>
<?= $message ?> </div>
<?php endif; ?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Order ID</th>
<th>User ID</th>
<th>Order Date</th>
<th>Order Time</th>
<th>Delivery Charge</th>
<th>Total Amount</th>
<th>Address</th>
<th>Coordinates</th>
<th>Driver Number</th>
<th>Order Status</th>
<th>Action</th>
</tr>
</thead>
<?php
/*** * DISPLAY TABLE */
?>
<tbody>
<?php if ($orders): ?>
<?php
while ($order = mysqli_fetch_array($orders, MYSQLI_BOTH)):
?>
<?php
$order_datetime = $order['order_datetime'];
$date = date('Y-m-d', strtotime($order_datetime));
$time = date('H:i:s', strtotime($order_datetime));
?>
<tr>
<td><?= $order['order_id'] ?></td>
<td><?= $order['user_id'] ?></td>
<td><?= $date ?></td>
<td><?= $time ?></td>
<td><?= $order['order_deliveryCharge'] ?></td>
<td><?= $order['order_totalAmount'] ?></td>
<td><?= $order['address'] ?></td>
<td><?= $order['coordinates'] ?></td>
<td><?= $order['driver_number'] ?></td>
<td><?= $order['order_status'] ?></td>
<td><button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="viewOrder( '<?= $order['order_id'] ?>', '<?= $order['order_id'] ?>', '<?= $date ?>', '<?= $time ?>', '<?= $order['order_deliveryCharge'] ?>', '<?= $order['order_totalAmount'] ?>', '<?= $order['address'] ?>', '<?= $order['coordinates'] ?>', '<?= $order['driver_number'] ?>', '<?= $order['order_status'] ?>')"> View Order </button>
</td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<script>
function viewOrder(order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) {
document.getElementById("titleModal").innerHTML = "viewOrder";
document.getElementsByName("order_id")[0].setAttribute("value", order_id);
document.getElementsByName("user_id")[0].setAttribute("value", user_id);
document.getElementsByName("order_date")[0].setAttribute("value", order_date);
document.getElementsByName("order_time")[0].setAttribute("value", order_time);
document.getElementsByName("order_deliveryCharge")[0].setAttribute("value", order_deliveryCharge);
document.getElementsByName("order_totalAmount")[0].setAttribute("value", order_totalAmount);
document.getElementsByName("address")[0].setAttribute("value", address);
document.getElementsByName("coordinates")[0].setAttribute("value", coordinates);
document.getElementsByName("driver_number")[0].setAttribute("value", driver_number);
document.getElementsByName("order_status")[0].setAttribute("value", order_status);
document.getElementsByName("viewOrder")[0].setAttribute("name", "viewOrder");
/*x = document.getElementsByName("order_status").value;
if(x == "Accepted"){
document.getElementsByName("submitAccept").disabled = true;
}*/
}
</script?
</body>
</html>
And this is the ordermodal.php
UI of ordermodal.php
<?php
/** *ordermodal.php **/
$id = "";
$order_date = "";
$order_time = "";
$order_id = "";
$order_deliverCharge = "";
$order_status = "";
$order_totalAmount= "";
$coordinates = "";
$driver_number = "";
$address = "";
$food_name="";
$special_request="";
$quantity="";
$amount="";
$orders="";
?>
<!-- MODALS --> <!-- DETAILS -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form action="" method="post" class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><center>×</button>
<h4 class="modal-title" id="titleModal"></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_id" id="order_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="id" class="col-sm-2 control-label">ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_date" class="col-sm-2 control-label">Order Date</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_time" class="col-sm-2 control-label">Order Time</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Address</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="coordinates" class="col-sm-2 control-label">Coordinates</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
</div>
</div>
<div class="form-group">
<label for="driver_number" class="col-sm-2 control-label">Driver Number</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="driver_number" id="driver_number" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_status" class="col-sm-2 control-label">Order Status</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
// This is where I want to get the value of oder_id from order.php page
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection(), $sql);
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
<tbody>
</div>
<div class="modal-footer">
<button type="submit" name="showOrder" id="showOrder" class="btn btn-secondary" onclick="" > Show Order </button>
<button type="submit" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
<button type="submit" name="submitSent" class="btn btn-primary"onclick="if(!confirm('Are you sure you want to send order?')){return false;}" >Sent</button>
<button type="submit" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
<?php
if(isset($_POST['showOrder'])){
$order_id = trim(addslashes($_POST['order_id']));
}
if(isset($_POST['submitAccept'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Accepted"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitSent'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Dispatched' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Dispatched"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitCancel'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Cancelled"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
?>
</div>
</form>
</div>
</div>
</div>
So the function of this as the moment is when clicked the view order the value of the order_id from order.php didnt get, you need first to click the button inside the ordermodal.php(accept,send,cancel) in order to get the value of order_id.
"When I click the view order, I'll get right away the value of order_id so that I can use it in my sql query. This is what supposed to be the real output."
Hope you guys can help me, I stacked at this error for a couple of days already. TIA!
Couldn't you still use the session var you did in the first chunk...unless you are reseting that value - but didn't see that...
Alternatively... the url you are calling to get the url for the modal you could put a query param of OID=# and than do the typical...
$orderID = $_GET['old'] ? $_GET['old'] : $_POST['old']; // not sure if your posting or just doing a get....
Also no sure if your pulling this in through an iframe or what not but either way query param or session var should work.
Hope this helps.

Using radio buttons to show approved or unapproved users in admin panel in php mysql

I have a project wherein I need to show unapproved and approved user from the database. I have to show it by radio buttons such as All, Approved and Unapproved. I want to know how to list each of them ,as the radio choice is clicked, on the same page. I am a fresher in PHP and its my first project and so highly confused.
I am trying to put in switch for radio and no idea about how to write MySQL query in each switch case. Is there any solution or code available? Is there any way to solve this?
Here is my code:
<?php include 'blocks/headerInc.php' ; ?>
<?php
$errmsg = "" ;
$module_id = '';
$query = '';
$date_from = '';
$date_to = '';
//Search section start here
$sqlQuery = "SELECT * FROM tbl_user WHERE type =3 " ;
if(isset($_REQUEST['submit']))
{
if(!empty($_REQUEST['date_from']))
{
$date_from = date("Y-m-d", strtotime($_REQUEST['date_from'])) ;
}
if(!empty($_REQUEST['date_to']))
{
$date_to = date("Y-m-d", strtotime($_REQUEST['date_to'])) ;
}
if(!empty($date_to) && empty($date_from))
{
$errmsg = "Please select valid date range.";
}
if(!empty($date_to) && (strtotime($date_from)> strtotime($date_to)))
{
$errmsg = "Please select valid date range.";
}
if($errmsg =='')
{
if(!empty($date_to) && (strtotime($date_from)<= strtotime($date_to)))
{
$sqlQuery .= " AND created_on BETWEEN '$date_from' AND '$date_to'";
}
$sqlQuery .= " order by id DESC";
}
$date_from = date("m/d/Y",strtotime($date_from));
$date_to = date("m/d/Y",strtotime($date_to));
$date_from = $date_from != '01/01/1970' ? $date_from : '';
$date_to = $date_to != '01/01/1970' ? $date_to : '';
}
?>
<div class="container pagecontainer">
<!-- Static navbar -->
<div class="row row-offcanvas row-offcanvas-right">
<!--/.col-xs-12.col-sm-9-->
<div class="col-sm-3 col-md-3 sidebar" id="sidebar">
<div id="left_panel" class="clearfix left">
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Search Registered Candidate</div>
<div class="panel-body">
<div class="column col-sm-offset-0">
<?php
if($errmsg!="")
{
echo "<div class='error'>".ucwords($errmsg)."</div>";
}
?>
<form class="form-horizontal" method="get" action="">
<div class="form-group">
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date From:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_from" placeholder="Date From" type="text" value="<?php echo $date_from ; ?>" >
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date To:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_to" placeholder="Date To" type="text" value="<?php echo $date_to ; ?>" >
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="col-md-8 text-left">
<button type="submit" name="submit" value="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Search</button>
<button type="reset" onClick="javascript:window.location.href='reportRegisteredUsers.php'" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Cancel</button>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label"> </label>
</div>
<div class="col-md-8 text-right">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Report:Candidate Reports</div>
<div class="panel-body">
<input type="radio" name="gender" value="male" checked="checked"> All Candidates<br>
<input type="radio" name="gender" value="female"> Approved Candidates<br>
<input type="radio" name="gender" value="other"> Unapproved Candidates<br>
<div class="column col-sm-offset-0">
<table id="example" class="table table-striped table-hover table-bordered dataTableReport dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>S.No.</th>
<th>Email ID</th>
<th>SBI Employee ID</th>
<th>Name</th>
<th>Mobile No.</th>
<th>Date of Birth</th>
<th>Registration Date</th>
</tr>
</thead>
<tbody>
<?php
$sq = $db->query($sqlQuery);
$i = 1 ;
if($db->affected_rows > 0)
{
while($row=mysql_fetch_array($sq))
{
extract($row);
?>
<tr>
<td><?php echo $i ; ?></td>
<td><?php echo $email ; ?></td>
<td><?php echo $employee_id ; ?></td>
<td><?php echo $first_name." ".$middle_name." ".$last_name ; ?></td>
<td><?php echo $mobile ; ?></td>
<td><?php if($dob !='1970-01-01'){echo date("d-m-Y", strtotime($dob)) ; }?></td>
<td><?php echo date("d-m-Y", strtotime($created_on)) ; ?></td>
</tr>
<?php $i++;}} ?>
</tbody>
</table>
</div>
</div>
</div>
<div> <button type="reset" onClick="javascript:history.go(-1)" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Go Back</button> </div>
<!--/row-->
</div>
<!--/.sidebar-offcanvas-->
</div>
</div>
<?php include 'blocks/footerInc.php'
This would be a very very simple page for what you want to archive.
<?php
//connection with database here.
if(isset($_POST['users']) && $_POST['users'] == 'approved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'unapproved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'other'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}
?>
<div>
<form action="" method="POST">
Approved<input type="radio" name="users" value="approved">
Unapproved<input type="radio" name="users" value="unapproved">
Other<input type="radio" name="users" value="other">
<input type="submit" value="Submit">
</form>
</div>
<div class="results">
<?php foreach ($users as $key => $value) {
?>
<div class="user">
<div><?php echo $value['firstName']; ?></div>
<div><?php echo $value['lastName']; ?></div>
</div>
<?php
} ?>
</div>

update form with 2 parts

hello everyone I am just starting PHP this year and I try to make form that is content 2 part first part main data second part it content table that I can add new row to enter data and this row content multi-select input and I try many times to write PHP code that I can update this form but I failed every time I try
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="shop_name">اسم المحل:
<a style="color: red">*</a>
</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="shop_name" value="<?php echo $strshop; ?>" name="shop_name" placeholder="اسم المحل" data-index="8">
</div>
<label class="control-label col-sm-2" for="cus_name">اسم العميل:
</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="cus_name" name="cus_name" value="<?php echo $strcus; ?>" placeholder="اسمع العميل" data-index="9">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="cus_address">العنوان:<a style="color: red">*</a></label>
<div class="col-sm-3">
<input type="text" class="form-control" id="cus_address" name="cus_address" value="<?php echo $straddres; ?>" placeholder="عنوان" data-index="10">
</div>
<label class="control-label col-sm-2" for="tel"> التليفون:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="tel" name="tel" value="<?php echo $strtel; ?>" placeholder="تليفون" data-index="11">
</div>
</div>
</div>
<div class="modal-footer">
<h2>مياه</h2>
<div class="row clearfix">
<div class="col-md-12 column">
<?php
if (!empty($strid)) {
$q2 = "SELECT * FROM product_table WHERE form_id = $strid;";
$result = mysqli_query($con, $q2);
$count = mysqli_num_rows($result);
?>
<table class="table table-bordered table-hover" id="data_table">
<thead>
<tr>
<th class="text-center">
المنتج
</th>
<th class="text-center">
SKus
</th>
<th class="text-center">
الكمية
</th>
<th class="text-center">
ثلاجات
</th>
<th class="text-center">
مواد دعائية
</th>
<th class="text-center">
كمية الدعايه
</th>
<th>
action
</th>
</tr>
</thead>
<tbody>
<?php
if ($count > 0) {
while ($wrow = mysqli_fetch_array($result)) {
?>
<tr id='row'>
<td>
<input hidden name="wid" value="<?php echo $wrow['id'] ?>">
<select class="form-control" id="product_name" name="product_name[]" data-index="12">
<option selected disabled hidden>اختار المنتج .....</option>
<?php
$select_water = $con->query("select * from water");
if ($select_water->num_rows > 0) {
// output data of each row
while ($w = $select_water->fetch_assoc()) {
?>
<option <?php if ($wrow['product_name'] == $w['water_name']) echo "selected";?> ><?php echo $w['water_name']?></option>
<?php
}
} else {
echo "0 results";
}
?>
</select>
</td>
<td>
<select class="form-control" id="sk" name="sk[]"
data-index="6">
<option selected disabled hidden>اختار Skus</option>
<?php
$select_area = $con->query("select * from watersk");
if ($select_area->num_rows > 0) {
// output data of each row
while ($row2 = $select_area->fetch_assoc()) {
?>
<option <?php if ($wrow['sk'] == $row2['sk_name']) echo "selected"; ?> ><?php echo $row2 ['sk_name'] ?></option>
<?php
}
} else {
echo "0 results";
}
?>
</select>
</td>
<td>
<input type="number" id="qty" name="qty[]" value="<?php echo $wrow['qty']; ?>" placeholder='الكميه' class="form-control" data-index="16"/>
</td>
<td>
<input type="number" id="friz" name="friz[]" value="<?php echo $wrow['frizer']; ?>" placeholder='ثلاجه' class="form-control" data-index="17"/>
</td>
<td>
<?php
// var_dump($row['id']);
$water_id = $wrow['id'];
$test_array=array();
$select_water_market = $con->query("SELECT * FROM product_market WHERE water_id = $water_id;");
while ($row3 = $select_water_market->fetch_assoc()) {
$test_array[]= $row3['watermarket_media'];
}
// var_dump($test_array);
?>
<select multiple class="form-control" id="market_medi" name="market_media[0][]" data-index="6">
<?php
$select_media = $con->query("select * from market_media");
if ($select_media->num_rows > 0) {
// output data of each row
while ($row = $select_media->fetch_assoc()) {
?>
<?php if(in_array($row['media_name'],$test_array)){?>
<option selected>
<?php echo $row ['media_name'] ?>
</option>
<?php
}
else
{?>
<option>
<?php echo $row ['media_name'] ?>
</option>
<?php }
}
}else {
echo "0 results";
}
?>
</select>
</td>
<td>
<input style="float: right" type="number" id="market" name="market[]" placeholder="مواد دعائيه" class="form-control" value="<?php echo $wrow['mark_qty']; ?>" data-index="18"/>
</td>
<td>
<a class="btn btn-warning btn-sm" href='save/deleterow.php?id=".$delete['id']." data-toggle="modal" style="float: left;"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-danger btn-sm" href='save/deleterow.php?id=<?php echo $wrow['id'];?>&stid=<?php echo $strid;?>' data-toggle="modal" style="float: left;"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
<a class="btn btn-success btn-sm" href="" data-toggle="modal" onclick="addVariablesRow();" style="float: left;"><span class="glyphicon glyphicon-plus"></span></a>
</div>
<script>
function deleterow2(o) {
//no clue what to put here?
var p = o.parentNode.parentNode;
p.parentNode.removeChild(p);
}
var i = 1;
function addVariablesRow() {
var $t = $("#data_table");
var $row = $t.find("tbody tr").first();
var $r = $row.clone();
$r.attr('id', 'rrow' + i);
var $newRow = $r.find('input').val('').end().append("<td><a class='btn btn-danger btn-sm delete' onclick='deleterow2(this);' style='float: left;'><span class='glyphicon glyphicon-trash'></span></a></td>");
$newRow.appendTo($t).show();
$("#data_table tr:last td:first select").focus();
$('#market_medi').each(function () {
$(this).attr('name', 'market_media[' + i + '][]');
});
i++;
}
</script>
</div>
</div>

ajax and a form with post method

I have a problem with a form that is used to insert data into a table, I need it to show a message if the data is inserted correctly or not. by the way, the actual code is not inserting anything to the table, but if I use directly the php file used to insert it, it works.
this is the file with the form and the script:
registrarrack.php
<?php
include('conexion.php');
session_start();
?>
<html>
<head>
<title>Inicio</title>
<link rel="stylesheet" type="text/css" href="style/stylef.css">
<link rel="stylesheet" type="text/css" href="style/style.css">
<script src="js/jquery-1.12.4.js"></script>
<script> function myFunction() {
document.getElementsByClassName("topnav")[0].classList.toggle("responsive");
}
function justNumbers(e)
{
var keynum = window.event ? window.event.keyCode : e.which;
if ((keynum == 8))
return true;
return /\d/.test(String.fromCharCode(keynum));
}
function showContent() {
element = document.getElementById("content");
check = document.getElementById("check");
if (check.checked) {
element.style.display='block';
}
else {
element.style.display='none';
}
}
</script>
</head>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________-->
<script>
function Validar(Noserie, WO, Locacion, Modelo)
{
$.ajax({
url: "registrarrackbackend.php",
type: "POST",
data: "Noserie="+Noserie+"&WO="+WO+"&Locacion="+Locacion+"&Modelo="+Modelo,
success: function(resp){
$('#resultado').html(resp)
}
});
}</script>
<!-- _________________________________________________________________End of AJAX Script___________________________________________________________________________-->
<body class="desarroll">
<header>
<div class="grupo">
<div class="caja">
<center><nav>
<ul class="topnav">
<li>| Inicio |</li>
<li>| Estatus |</li>
<li>| Buscar nodo |</li>
<li>| Buscar rack |</li>
<li>| Estadisticas |</li>
<?php if(isset($_SESSION['Nombrers'])){ echo '<li>| Cerrar Sesion |</li>';}else{echo '<li>| Iniciar Sesion |</li>';}?>
<li class="icon">
☰</li>
</ul>
</nav></center>
</div>
</div>
<?php if(isset($_SESSION['Nombrers'])){
echo '<center><div class="nombre" align="center">| '.$_SESSION['Nombrers'].' | '.$_SESSION['Mesamensrs'].' </div></center>';
}?>
</header>
<section>
<!-- ********************LOGIN***********************************-->
<?php
$query = mysqli_query($enlace, "SELECT Numero FROM mesas WHERE EnUso = '0'");
if(!isset($_SESSION['Nombrers'])){
echo '<center> <div id="modal">
<div class="modal-content ">
<div class="header">
<h2>Iniciar sesión</h2>
<center><hr width="150" align="center"/></center>
</div>
<div class="copy">
<div class="grupo">
<div class="caja">
<form method="post" action="login.php" class="login">
<label style="color:#1BBC9B; font-weight:bold;">
<input type="checkbox" style="width:0px; display:relative;" name="check" id="check" value="1" onchange="javascript:showContent()" >¿Técnico de reparación?</label><br>
<div id="content" style="display: none;">
<b>Mesas disponibles :
<input type="radio" name="mesa" style="width:0px; " value="0" checked="checked"> ';
while ($datos=mysqli_fetch_row($query) ) {
echo '<label><input type="radio" name="mesa" value="'.$datos[0].'" style="color:black; width:30px;">'.$datos[0].'</label> ';
}
echo '</b>
</div>
<input type="text" name="NoReloj" placeholder="Número de reloj" required maxlength="5" onkeypress="return justNumbers(event);">
<input type="password" name="Pass" placeholder="Contraseña" required>
<input type="hidden" name="Url" value="index.php#">
</script>
<button class="btn1">Aceptar</button>
<input class="btn2" type="button" value="Cerrar" onClick="window.location.href=\'#\'">
</form>
</div>
</div>
</div>
</div>
<div class="overlay"></div>
</div></center>'
;
}
echo '<center> <div id="modalmesa">
<div class="modal-content ">
<div class="header">
<h2>Elegir mesa</h2>
<center><hr width="150" align="center"/></center>
</div>
<div class="copy">
<div class="grupo">
<div class="caja">
<form method="post" action="elegirmesa.php" class="login">
<div id="resultado"></div>
<input type="hidden" name="Url" value="index.php#">
</script>
<button class="btn1">Aceptar</button>
</form>
</div>
</div>
</div>
</div>
<div class="overlay"></div>
</div></center>'
;
?>
<!-- _________________________________________________________________Form___________________________________________________________________________-->
</section>
<center>
<?php $query = mysqli_query($enlace, "SELECT Nombre FROM familia"); ?>
<div class="grupo-centar">
<div class="caja">
<br><br>
<h2>Registrar rack</h2><br>
<div id="resultado"></div>
<table class="tablaregistro">
<tr>
<form class="RegistroR" method="POST" action="return false" onsubmit="return false" id="formregistro">
<td><input type="text" name="Noserie" id="Noserie" placeholder="Número de serie" required form="formregistro" maxlength="10" pattern=".{10,}" ></td>
</tr>
<tr>
<td><input type="text" name="WO" id="WO" placeholder="WO" required form="formregistro" maxlength="9" pattern=".{9,}"></td>
</tr>
<tr>
<td><input type="text" name="Locacion" id="Locacion" placeholder="Locación: TRXX-XX" required form="formregistro" maxlength="8" pattern=".{7,}"></td>
</tr>
<tr>
<td><Select name="Modelo" id="Modelo" required form="formregistro" placeholder="Modelo">
<option value="" disabled selected>Modelo</option>
<?php
while ($datos=mysqli_fetch_row($query) ) {
echo '<option value="'.$datos[0].'">'.$datos[0].'</option>';
}
?>
</Select></td>
</tr>
<tr>
<td><Button class="btnregistrar" form="formregistro" onclick="Validar(document.getElementById('Noserie').value, document.getElementById('WO').value, document.getElementById('Locacion').value, document.getElementById('Modelo').value);"><h1>Registrar</h1></Button></td>
</tr>
</table>
</form>
</center>
</div>
</div>
<section>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________-->
</body>
</html>
and heres the other php file:
registrarrackbackend.php
<?php
error_reporting(0);
include('conexion.php');
session_start();
$NoSerie = $_POST['Noserie'];
$Locacion = $_POST['Locacion'];
$WO = $_POST['WO'];
$Familia = $_POST['Modelo'];
$Tecnico = $_SESSION['No_Relojrs'];
$consulta=mysqli_query($enlace, "SELECT * FROM rack WHERE NoSerie= '$NoSerie'");
if($cons=mysqli_fetch_array($consulta)){
echo '<span>Error: rack is already registered</span>';
}else{
$sql2="INSERT INTO rack (NoSerie, WO, Familia, Locacion, Tecnico) VALUES ('$NoSerie','$WO' ,'$Familia','$Locacion','$Tecnico')";
if(mysqli_query($enlace, $sql2)){
//echo "<script>location.href = 'index.php'</script>";
echo '<span>rack was successfully registered</span>';
}else{echo "<span>Error updating record: " . mysqli_error($conn).'</span>';}
}
?>
I don't know what is wrong with the code, I hope you can help me please. and sorry for my bad english

insert multiple table rows via a php into mysql

I am inserting multiple line values from a html table form in to sql but it's only inserting the last table form value in my database. I can't figure out where the problem is.
Can you help me out with this?
This is my PHP:
$result = mysql_query("SELECT * FROM ex_marks WHERE session='$session' and cl_name='$cl_name' and cl_section='$cl_section' and subject='$subj' and exam='$exam' and date='$date' and roll_no='$rollno' and obtainmarks='$marks'");
if (mysql_num_rows($result) == 0)
{
mysql_query("INSERT INTO ex_marks(mid, session, cl_name, cl_section, name, fname, status, date, exam, roll_no, subject, obtainmarks, maxmarks, passmarks)
VALUES('', '$session', '$cl_name', '$cl_section', '$name','$fname', '$attendance', '$date', '$exam', '$rollno', '$subj','$marks','$maxmarks','$passmarks')") or die(mysql_error());
echo "<script type='text/javascript'>alert('Submitted Successfully!')</script>";
}
else
{
echo "<script type='text/javascript'>alert('Already Exist!')</script>";
}
}
And this is the form where values are inserted:
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">ASSIGN MARKS</h1>
<div class="col-lg-6">
<div class="panel">
<form method="post">
<!--<div class="form-group">
<input type="text" size="15" name="date" id="name[]" class="tcal form-control" placeholder="EXAM DATE" required="required"/>
</div>-->
<div class="form-group">
<input class="form-control" type="text" size="17" name="maxmarks" placeholder="TOTAL MARKS" required="required"/>
</div>
<div class="form-group">
<input class="form-control" type="text" size="17" name="passmarks" placeholder="PASS MARKS" required="required"/>
</div>
<button name="btn_sub" type="submit" class="btn btn-info">SUBMIT</button>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Session :
<?php
$session=$_GET['session'];
echo $session;?>
Class :
<?php
$cl_name=$_GET['cl_name'];
echo $cl_name;?>
Section :
<?php
$cl_section=$_GET['cl_section'];
echo $cl_section;?>
Subject :
<?php
$subj = $_GET['subj'];
echo $subj;?>
Exam Date :
<?php
$date=$_GET['date'];
echo $date;?>
Exam :
<?php
$exam=$_GET['exam'];
echo $exam;?>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>NO.</th>
<th class="text-center">NAME</th>
<th class="text-center">ROLL NO</th>
<th class="text-center">FATHER NAME</th>
<th class="text-center">SCORED MARKS</th>
<th class="text-center">ATTENDANCE</th>
</tr>
</thead>
<tbody>
<?php
$key="";
if(isset($_POST['searchtxt']))
$key=$_POST['searchtxt'];
if($key !="")
$sql_sel1=mysql_query("SElECT * FROM ex_attendance WHERE session like '%$key%' and cl_name like '%$key%' and cl_section like '%$key%'");
else
$sql_sel1=mysql_query("select * from ex_attendance where session='$session' and cl_name='$cl_name' and cl_section='$cl_section' and exam='$exam' and date='$date' and subject='$subj'");
$i=0;
while($row1=mysql_fetch_array($sql_sel1))
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr class="odd gradeX">
<td><?php echo $i;?></td>
<td align="center"><input size="17" type="text" name="name" value="<?php echo $row1['f_name']." ".$row1['m_name']." ".$row1['l_name'];?>" readonly="readonly"/></td>
<td align="center"><input size="13" type="text" name="rollno" value="<?php echo $row1['roll_no']?>" readonly="readonly"/></td>
<td align="center"><input size="17" type="text" name="fname" value="<?php echo $row1['fname']?>" readonly="readonly"/></td>
<td align="center"><input size="17" type="text" name="marks" required="required"/></td>
<td align="center"><input size="17" type="text" name="attendance" id="name[]" value="<?php echo $row1['status'];?>" readonly="readonly"/></td>
</tr>
<?php }?>
</form>
</tbody>
</table>
</div>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</div>

Categories