Im trying to make a Shopping Cart using php and Bootstrap 5. I specified the classes but the items still stacks vertically. I want it to be beside each other and align Horizontally
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>shopping cart</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="cart.css">
</head>
<body>
<div class="container">
<?php
$connect = mysqli_connect('localhost','root','1234','cart');
$query = 'SELECT * FROM products ORDER by id ASC';
$result = mysqli_query($connect, $query);
if ($result) {
if(mysqli_num_rows($result)>0){
while($product = mysqli_fetch_assoc($result)){
?>
<div class="row">
<div class="col-sm-4 col-md-3">
<form method="post" action="index.php?action=add&id=<?php echo $product['id']; ?>">
<div class="products">
<img class="img-fluid" src="<?php echo $product['image']; ?>">
<h4 class="text-info"><?php echo $product['name']; ?></h4>
<h4>$ <?php echo $product['price']; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="name" value="<?php echo $product['name']; ?>"/>
<input type="hidden" name="price" value="<?php echo $product['price']; ?>"/>
<input type="submit" name="add_to_cart" class="btn btn-info" value="Add to Cart"/>
</div>
</form>
</div>
</div>
<?php
}
}
}
?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>
is there something that im missing?? I tried evrything that i know of T^T
ps. Im still a novice when it comes to Web Developing so please have mercy on me T^T ;3
You have a "row" around each "column", that means each row has only one column. Try to put the "row" outside the loop so multiple columns fall within it. You can have as many columns in a row as you like. Something like this:
<?php
if ($result) {
if(mysqli_num_rows($result)>0){
?>
<div class="row">
<?php
while($product = mysqli_fetch_assoc($result)){
?>
<div class="col-sm-4 col-md-3">
<form method="post" action="index.php?action=add&id=<?php echo $product['id']; ?>">
<div class="products">
<img class="img-fluid" src="<?php echo $product['image']; ?>">
<h4 class="text-info"><?php echo $product['name']; ?></h4>
<h4>$ <?php echo $product['price']; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="name" value="<?php echo $product['name']; ?>"/>
<input type="hidden" name="price" value="<?php echo $product['price']; ?>"/>
<input type="submit" name="add_to_cart" class="btn btn-info" value="Add to Cart"/>
</div>
</form>
</div>
<?php
}
?>
</div>
<?php
}
}
?>
</div>
<?php
if (mysqli_num_rows($result) > 0) {
echo '<div class="row">';
while ($product = mysqli_fetch_assoc($result)) {
?>
<div class="col-sm-4 col-md-3">
<form method="post" action="index.php?action=add&id=<?php echo $product['id']; ?>">
<div class="products">
<input type="hidden" name="name" value="<?php echo $product['name']; ?>" />
<input type="hidden" name="price" value="<?php echo $product['price']; ?>" />
<!-- I think you need rows inside form tag -->
<div class="row">
<div class="col-sm-4 col-md-3">
<img class="img-fluid" src="<?php echo $product['image']; ?>">
</div>
<div class="col-sm-4 col-md-3">
<h4 class="text-info"><?php echo $product['name']; ?></h4>
</div>
<div class="col-sm-4 col-md-3">
<h4>$ <?php echo $product['price']; ?></h4>
</div>
<div class="col-sm-4 col-md-3">
<input type="text" name="quantity" class="form-control" value="1" />
</div>
<div class="col-sm-4 col-md-3">
<input type="submit" name="add_to_cart" class="btn btn-info" value="Add to Cart" />
</div>
</div> <!-- ./row -->
</div>
</form>
</div>
<?php
} // end while
echo '</div>';
} // end if
?>
Related
I have a problem, when I retrieve the value from the $_POST variable, the value taken is the last value printed.
<?php
foreach($mlbb as $s){
?>
<div class="col-lg-4 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3><?php echo $s->layanan."<br>".$s->harga." Poin" ?></h3>
</div>
<form action="<?php echo base_url(). 'mlbb/beli_aksi'; ?> " method="post" id="form-satuan" >
<input type="hidden" name="id" class="form-control" value="<?php echo $s->id;?>">
<input type="hidden" name="harga" class="form-control" value="<?php echo $s->harga;?>">
<input type="submit" class="btn btn-success" value="Beli">
</div>
</div>
<!-- ./col -->
<?php } ?>
I am new in php. I have a PHP script which auto generates a tracking number in mysql database cons_no is the name of the table, I wish to enter the cons_no data manually.
Also when I try to edit the cons_no value from the edit page, other things are allowed to be edited - except con_no. Any help will be appreciated.
This is the code that creates the the file with the cons_no value.
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
session_start();
//Include database configuration file
require_once('database-settings.php');
require_once('database.php');
$db = conexion();
require_once('library.php');
require_once('funciones.php');
require 'requirelanguage.php';
include_once "filtro/class/class.php";;
include_once "filtro/class_buscar.php";
require_once("filtro/class/class.inputfilter.php");
$ifilter = new InputFilter();
$_POST = $ifilter->process($_POST);
$sql = "SELECT DISTINCT(off_name)
FROM offices";
$result = dbQuery($sql);
$company=mysql_fetch_array(mysql_query("SELECT * FROM company"));
date_default_timezone_set($_SESSION['ge_timezone']);
$fechai=date('Y-m-d');
$fechaf=date('Y-m-d');
isUser();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $_SESSION['ge_cname']; ?> | <?php echo $ENVIOS; ?></title>
<meta name="description" content="<?php echo $_SESSION['ge_description']; ?>"/>
<meta name="keywords" content="<?php echo $_SESSION['ge_keywords']; ?>" />
<meta name="author" content="Jaomweb">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="shortcut icon" type="image/png" href="img/favicon.png"/>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="../bower_components/animate.css/animate.css" type="text/css" />
<link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css" type="text/css" />
<link rel="stylesheet" href="../bower_components/simple-line-icons/css/simple-line-icons.css" type="text/css" />
<link rel="stylesheet" href="css/font.css" type="text/css" />
<link rel="stylesheet" href="css/app.css" type="text/css" />
<link href="css/style.css" rel="stylesheet" media="all">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
<!-- Switchery css -->
<link href="assets/plugins/switchery/switchery.min.css" rel="stylesheet" />
<!-- Plugins css -->
<link href="assets/plugins/timepicker/bootstrap-timepicker.min.css" rel="stylesheet">
<link href="assets/plugins/mjolnic-bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
<link href="assets/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="assets/plugins/clockpicker/bootstrap-clockpicker.min.css" rel="stylesheet">
<link href="assets/plugins/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">
</head>
<body>
<?php
include("header.php");
?>
<!-- content -->
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="wrapper-md">
<div class="row">
<div class="col-sm-12">
<div class="blog-post">
<div class="panel">
<div class="wrapper-lg">
<div>
<tbody>
<div class="row alertaCaja" style="display: none;">
<div class="col-xs-4 col-sm-4 col-md-4" style="float: none; margin: 0 auto;">
<div class="alert alert-dismissible alert danger">
<button type="button" class="close" data-dismiss="alert"><img src="img/close.png" height="15" width="15"></button>
<center>
<?php
require_once('database.php');
$query= mysql_query("SELECT MAX(cid) AS id FROM courier");
if ($row = mysql_fetch_row($query))
{
?>
<a target="_blank" href="print-invoice/invoice-print.php?cid=<?php echo codificar($id = trim($row[0])); ?>">
<img src="img/print-invoice.png" height="76" width="79"></a>
<?php } ?>
<?php
require_once('database.php');
$query= mysql_query("SELECT MAX(cid) AS id FROM courier");
if ($row = mysql_fetch_row($query))
{
?>
<a target="_blank" href="print-invoice/ticket-print.php?cid=<?php echo codificar($id = trim($row[0])); ?>">
<img src="img/print_label.png" height="76" width="79"></a>
<?php } ?>
</center>
</div>
</div>
</div>
<?php if ( isset ( $_GET ['tipo'] ) ) { ?>
<div class="row alertaCaja" style="display: none;" >
<div class="col-xs-6 col-sm-6 col-md-6" style="float: none; margin: 0 auto;">
<div class="alert alert-dismissible alert-<?php echo $_GET ['tipo'] ?>">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong><?php echo $L_['message']; ?></strong><br/><br/> <?php echo $_GET ['mensaje']; ?>
</div>
</div>
</div>
<?php } ?>
<tr>
<h3 class="classic-title"><span><strong><i class="fa fa-truck icon text-default-lter"></i> <?php echo $ADICIONAR; ?></strong></h3>
<!-- START Checkout form -->
<form action="settings/add_courier/agregar.php" method="post" >
<table border="0" align="center" width="100%" >
<div class="row">
<!-- START Presonal information -->
<fieldset class="col-md-6">
<legend><?php echo $datosremite; ?></legend>
<!-- Name -->
<div class="row" >
<div class="col-sm-2 form-group">
<label class="control-label"><i class="fa fa-user icon text-default-lter"></i> <?php echo $StaffRole; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="officename" id="officename" value="<?php echo $_SESSION['user_type'] ;?>" readonly="true" />
</div>
<div class="col-sm-2 form-group">
<label class="control-label"><i class="fa fa-user icon text-default-lter"></i> <?php echo $StaffUser; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="user" id="user" value="<?php echo $_SESSION['user_name'] ;?>" readonly="true" />
</div>
<div class="col-sm-8 form-group">
<label class="control-label" ><?php echo $NOMBREREMITENTE; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="Shippername" id="Shippername" autocomplete="on" list="customers" />
<datalist id="customers">
<?php
$sql=mysql_query("SELECT * FROM tbl_clients");
while($row=mysql_fetch_array($sql)){
echo '<option data-value="'.$row['id'].'">'.utf8_encode($row['name']).'</option>';
}
?>
</datalist>
<input type="hidden" name="Shippername-hidden" id="Shippername-hidden" />
</div>
</div>
<div class="row">
<div id="divRemi">
<div class="col-sm-6 form-group">
<label class="control-label"><?php echo $DIRECCION; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="Shipperaddress" id="Shipperaddress" placeholder="<?php echo $placeremi; ?>" />
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-phone icon text-default-lter"></i> <?php echo $TELEFONO; ?></label>
<input type="tel" class="form-control" name="Shipperphone" id="Shipperphone" placeholder="<?php echo $placetele; ?>" />
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><?php echo $CEDULA; ?></i></label>
<input type="text" class="form-control" name="Shippercc" id="Shippercc" placeholder="<?php echo $placeced; ?>" >
</div>
<div class="col-sm-3 form-group" style="display:none">
<label class="control-label"><?php echo $L_['lockerid']; ?></i></label>
<input type="text" class="form-control" name="Shipperlocker" id="Shipperlocker" placeholder="<?php echo $L_['lockerid']; ?>">
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-angle-double-right icon text-default-lter"></i> <strong><?php echo $PAISORIGEN; ?></strong></label>
<input type="text" class="form-control" name="Pickuptime" id="Shippercountry" placeholder="<?php echo $L_['placecountry']; ?>">
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $L_STATE; ?></strong></label>
<input type="text" class="form-control" name="state" id="Shipperstate" placeholder="<?php echo $L_['placestate']; ?>">
</div>
<div class="col-sm-3 form-group" style="display:none">
<label class="control-label"><strong><?php echo $CODIGO; ?></strong></label>
<input type="text" class="form-control" name="iso" id="Shipperiso" placeholder="<?php echo $L_['placeiso']; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $CIUDAD; ?></strong></label>
<input type="text" class="form-control" id="Shipperciudad" name="ciudad" placeholder="<?php echo $L_['placecity']; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $CODIGOPOSTAL; ?></strong></label>
<input type="text" class="form-control" id="Shipperzipcode" name="zipcode" placeholder="<?php echo $codigopostal; ?>">
</div>
<div class="col-sm-12 form-group">
<p class="error"></p>
<label class="control-label"><?php echo $EMAIL; ?><font color="#FF6100"><?php echo $notaemail; ?></font></i></label>
<input type="email" class="form-control" name="Shipperemail" id="idemail" placeholder="demo#emo.com" autocomplete=" off" onKeyUp="javascript:validateeMail('idemail')" />
<strong><span id="mailOK"></span></strong>
<p class="error"></p>
</div>
</div>
</div>
<!-- Adress and Phone -->
<!-- START Shipment information -->
</br></br>
<legend><?php echo $Informaciondeenvio; ?></legend>
<div class="row">
<!-- Origin Office -->
<div class="col-sm-3 form-group">
<label for="zipcode" class="control-label"><i class="fa fa-angle-double-right icon text-default-lter"></i> <strong><?php echo $OFICINAORIGEN; ?></strong></label>
<select class="form-control" name="Invoiceno">
<?php
while($data = dbFetchAssoc($result)){
?>
<option value="<?php echo $data['off_name']; ?>"><?php echo $data['off_name']; ?></option>
<?php
}//while
?>
</select>
</div>
<div class="col-sm-3 form-group">
<label for="ccv" class="control-label"><strong><?php echo $CantidadPaquetes; ?></strong></i></label>
<input type="number" class="form-control" name="Qnty" placeholder="<?php echo $placecant; ?>" />
</div>
<!-- Text area -->
<div class="col-sm-6 form-group">
<label for="inputTextarea" class="control-label"><i class="fa fa-comments icon text-default-lter"></i> <?php echo $DetallesdelEnvio; ?></label>
<textarea class="form-control" name="Comments" placeholder="<?php echo $placedetails; ?>" ></textarea>
</div>
</div>
<div class="row">
<div class="col-sm-5 form-group">
<label class="control-label"><i class="fa fa-database icon text-default-lter"></i> <strong><?php echo $Pagos; ?></strong></label>
<select class="form-control" name="bookingmode">
<option selected="selected" value="Effective"><?php echo $Effective; ?></option>
<option value="Debit_card"><?php echo $Debitcard; ?></option>
<option value="Credit_card"><?php echo $Creditcard; ?></option>
<option value="Transfer"><?php echo $Transfer; ?></option>
<option value="Online"><?php echo $Payonline; ?></option>
<option value="Paypal"><?php echo $L_['type_paypal']; ?></option>
</select>
</div>
<div class="col-sm-4 form-group">
<label class="control-label"><?php echo $TipodeProducto; ?></label>
<select type="text" class="form-control" name="Shiptype" >
<?php
$sql="SELECT name FROM type_shipments GROUP BY name";
$query=$db->query($sql);
if($query->num_rows>0){
while($row=$query->fetch_array()){
echo '<option data-value="'.$row['name'].'">'.utf8_encode($row['name']).'</option>';
}
}
?>
</select>
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-plane icon text-default-lter"></i> <?php echo $MododelServicio; ?></label>
<select class="form-control" name="Mode">
<?php
$sql="SELECT name FROM mode_bookings GROUP BY name";
$query=$db->query($sql);
if($query->num_rows>0){
while($row=$query->fetch_array()){
echo '<option data-value="'.$row['name'].'">'.utf8_encode($row['name']).'</option>';
}
}
?>
</select>
</div>
</div>
<!-- Payment Mode -->
<div class="row">
<div class="col-sm-3 form-group" >
<label class="text-danger"><strong><?php echo $_SESSION['ge_curr']; ?> <?php echo $ValorDeclarado; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum2" name="Totaldeclarate" value="0" />
</div>
<div class="col-sm-3 form-group" >
<label class="text-danger"><strong><?php echo $Declarado; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum5" name="Totaldeclarado" value="4" />
</div>
<div class="col-sm-3 form-group">
<label for="ccv" class="text-danger"><strong><?php echo $_SESSION['ge_curr']; ?> <?php echo $ValorRecogida; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum3" name="Totalfreight" value="0" />
</div>
<div class="col-sm-3 form-group">
<label class="text-danger"><strong><?php echo $_SESSION['ge_curr']; ?> <?php echo $PrimerKilo; ?> <?php echo $_SESSION['ge_measure']; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum1" name="variable" value="3.25" />
</div>
<div class="col-sm-3 form-group">
<label class="text-danger"><strong><?php echo $_SESSION['ge_curr']; ?> <?php echo $_SESSION['ge_measure']; ?> <?php echo $KiloAdicional; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum6" name="kiloadicional" value="3.25" />
</div>
<div class="col-sm-3 form-group">
<label class="text-danger"><strong><?php echo $PesoKg; ?> (<?php echo $_SESSION['ge_measure']; ?>)<strong></label>
<input type="text" class="form-control" required onblur="if(this.value == ''){this.value='0'}" onKeyUp="suma();" id="sum4" name="Weight" value="0" />
</div>
<div class="col-sm-3 form-group">
<label class="text-danger"><strong><?php echo $SubtotalEnvio; ?><strong></i></label>
<input type="text" class="form-control" name="shipping_subtotal" id="resultado" value="0" />
</div>
<div class="col-sm-3 form-group">
<label class="text-danger"><strong><?php echo $_SESSION['ge_curr']; ?> <?php echo $PesoFisico; ?><strong></label>
<input type="text" class="form-control" id="pesoreal" name="pesoreal" onblur="if(this.value == ''){this.value='0'}" >
</div>
</div>
<legend><?php echo $pesovolumetrico; ?>:</legend>
<!-- Peso Volumetrico -->
<div class="row">
<div class="col-sm-3 form-group">
<label class="text-primary"><strong><?php echo $Altura; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="volumetrico();" id="volume1" name="altura" placeholder="<?php echo $Altura; ?>" />
</div>
<div class="col-sm-3 form-group">
<label class="text-primary"><strong><?php echo $Ancho; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="svolumetrico();" id="volume2" name="ancho" placeholder="<?php echo $Ancho; ?>" />
</div>
<div class="col-sm-3 form-group">
<label class="text-primary"><strong><?php echo $Longitud; ?><strong></label>
<input type="text" class="form-control" onblur="if(this.value == ''){this.value='0'}" onKeyUp="volumetrico();" id="volume3" name="longitud" placeholder="<?php echo $Longitud; ?>" />
</div>
<div class="col-sm-3 form-group">
<label class="text-primary"><strong><?php echo $TotalPesoVolumetrico; ?><strong></i></label>
<input type="text" class="form-control" name="totalpeso" id="totalpeso" placeholder="0,00" />
</div>
</div>
</fieldset>
<!-- START Receiver info -->
<fieldset class="col-md-6">
<legend><?php echo $DatosDestinatario; ?></legend>
<!-- Name -->
<div class="form-group">
<label class="control-label"><?php echo $NOMBREDESTINATARIO; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="Receivername" id="Receivername" autocomplete="on" list="customers" >
</div>
<!-- Adress and Phone -->
<div class="row">
<div class="col-sm-3 form-group">
<label class="control-label"><?php echo $DIRECCION; ?><span class="required-field">*</span></label>
<input type="text" class="form-control" name="Receiveraddress" id="Receiveraddress" placeholder="<?php echo $placedirdesti; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-phone icon text-default-lter"></i> <?php echo $TELEFONO; ?></label>
<input type="tel" class="form-control" name="Receiverphone" id="Receiverphone" placeholder="<?php echo $placeteldesti; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-phone icon text-default-lter"></i> <?php echo $TELEFONO2; ?></label>
<input type="tel" class="form-control" name="telefono1" id="Receivertelefono1" placeholder="<?php echo $placeteldesti; ?>">
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><?php echo $CEDULA; ?></i></label>
<input type="text" class="form-control" name="Receivercc_r" id="Receivercc_r" placeholder="<?php echo $L_['placecedr']; ?>">
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><i class="fa fa-angle-double-right icon text-default-lter"></i> <strong><?php echo $PAISDESTINO; ?></strong></label>
<input type="text" class="form-control" name="paisdestino" id="Receivercountry1" placeholder="<?php echo $L_['placecountry1']; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $L_STATE; ?></strong></label>
<input type="text" class="form-control" name="state1" id="Receiverstate1" placeholder="<?php echo $L_['placestate']; ?>" >
</div>
<div class="col-sm-3 form-group" style="display:none">
<label class="control-label"><strong><?php echo $CODIGO; ?></strong></label>
<input type="text" class="form-control" name="iso1" id="Receiveriso1" placeholder="<?php echo $L_['placeiso']; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $CIUDAD; ?></strong></label>
<input type="text" class="form-control" name="city1" id="Receivercity1" placeholder="<?php echo $L_['placecity']; ?>" >
</div>
<div class="col-sm-3 form-group">
<label class="control-label"><strong><?php echo $CODIGOPOSTAL; ?></strong></label>
<input type="text" class="form-control" name="zipcode1" id="Receiverzipcode1" placeholder="<?php echo $codigopostal; ?>">
</div>
<div class="col-sm-12 form-group">
<p class="error"></p>
<label class="control-label"><?php echo $EMAIL; ?><font color="#FF6100"><?php echo $notaemail; ?></font></i></label>
<input type="email" class="form-control" name="Receiveremail" id="id_mail" placeholder="demo#emo.com" onKeyUp="javascript:validateMail('id_mail')" >
<strong><span id="emailOK"></span></strong>
<p class="error"></p>
</div>
</div>
</br></br>
<!-- Name -->
<div class="form-group">
<label for="name-card" class="text-success"><strong><?php echo $NUMEROENVIO; ?></strong></label>
<?php
$qryEmpresa = mysql_query("SELECT * FROM company");
while($row = mysql_fetch_array($qryEmpresa)) {
$pre = $row["prefijo"];
$cons = $row["cons_no"];
}
mysql_free_result($qryEmpresa);
$pa=mysql_query("SELECT MAX(cons_no)as maximo FROM c_tracking");
if($row=mysql_fetch_array($pa)){
if($row['maximo']==NULL){
$cons_no=''.$cons.'';
}else{
$cons_no=$row['maximo']+1;
}
}
?>
<input type="text" class="form-control" value="<?php echo $_SESSION['ge_prefix']; ?>-<?php echo "".$cons_no; ?>">
</div>
</br>
<!-- Status and Pickup Date -->
<div class="form-group">
<label for="dtp_input1" class="control-label"><i class="fa fa-calendar icon text-default-lter"></i> <?php echo $FECHARECOLECCIONENVIO; ?></i></label>
<div>
<div class="input-group">
<input type="text" class="form-control" name="Packupdate" placeholder="mm/dd/yyyy" id="datepicker-autoclose" >
<span class="input-group-addon bg-custom b-0"><i class="glyphicon glyphicon-calendar"></i></span>
</div><!-- input-group -->
</div>
</div>
<div class="row">
<div class="col-sm-4 form-group">
<label for="month" class="control-label"><i class="fa fa-sort-amount-asc icon text-default-lter"></i> <?php echo $estado; ?></label>
<select class="form-control" name="status" id="status">
<?php
$sql="SELECT servicemode FROM service_mode GROUP BY servicemode";
$query=$db->query($sql);
if($query->num_rows>0){
while($row=$query->fetch_array()){
echo '<option data-value="'.$row['servicemode'].'">'.utf8_encode($row['servicemode']).'</option>';
}
}
?>
</select>
</div>
<div class="col-sm-8 form-group">
<label for="dtp_input1" class="control-label"><i class="fa fa-calendar icon text-default-lter"></i> <?php echo $fechaestimadadeliver; ?></i></label>
<div>
<div class="input-group">
<input type="text" class="form-control" name="Schedule" placeholder="mm/dd/yyyy" id="datepicker">
<span class="input-group-addon bg-custom b-0"><i class="glyphicon glyphicon-calendar"></i></span>
</div><!-- input-group -->
</div>
</fieldset>
<div class="col-md-6 text-left">
</br></br>
<button type="submit" id="submit" class="btn btn-large btn-success"><?php echo $GUARDARENVIO; ?></button>
</div>
</div>
</div>
</div>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / content -->
<?php include("footer.php"); ?>
<?php include("footer_add_courier.php"); ?>
I have this list of DB entries in HTML and I wanted a edit button next to each row to be able to update the users info. The POST variables get to the .php file that updates the database row, the problem is that I can only edit the last row of the list, it seems like it submits the data via POST automatically. I would like to submit the data only after the Edit button has been pressed.
Show current member info and on-click redirect to a .php file where the query itself is executed
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
$id = $_POST['id'];
$query = "SELECT * FROM userinfo WHERE id LIKE $id";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/font-awesome.css">
<script src="js/jquery-2.1.4.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="well">
<form action="edit.php" class="form-horizontal well" method="post">
<fieldset>
<legend>Edit a member</legend>
<div class="row">
<div class="col-xs-8">
<div class="form-group">
<div class="rows">
<div class="col-md-8">
<div class="col-lg-6">
<input class="form-control input-lg" id="name" name="name" value="<?php echo $row['name'] ?>" type="text">
</div>
<div class="col-lg-6">
<input class="form-control input-lg" id="surname" name="surname" value="<?php echo $row['surname'] ?>" type="text">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="rows">
<div class="col-md-8">
<div class="col-lg-12">
<input class="form-control input-lg" id="address" name="address" value="<?php echo $row['address'] ?>" type="text">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="rows">
<div class="col-md-8">
<div class="col-lg-12">
<input class="form-control input-lg" id="number" name="number" value="<?php echo $row['number'] ?>" type="text">
<input type='hidden' name='id' value="<?php echo $row['id'] ?>">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="rows">
<div class="col-md-8">
<div class="col-lg-12">
<button class="btn btn-success btn-lg" type="submit">Update member details</button>
<div class="btn btn-info">View member DB</div>
</div>
</div>
</div>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div><!-- /container -->
</body>
</html>
Listing of current users (db rows)
<!DOCTYPE html>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
?>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/font-awesome.css">
<script src="js/jquery-2.1.4.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="well">
<h2 class="text-center">List of members</h2>
<hr width="75%">
<table class="table table-striped">
<thead>
<th width="6%" align="left">Member ID</th>
<th width="7%" align="left">First Name</th>
<th width="7%" align="left">Last Name</th>
<th width="7%" align="center">Address</th>
<th width="7%" align="center">Number</th>
<th width="7%" align="center">Edit</th>
</thead>
<tbody>
<?php
$query = 'SELECT * FROM userinfo';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo ' <tr> ';
echo ' <td> ';
echo $row['id'];
echo ' <td> ';
echo $row['name'];
echo ' <td> ';
echo $row['surname'];
echo ' <td> ';
echo $row['address'];
echo ' <td> ';
echo $row['number'];
echo "<td><form action='info.php' method='POST'><input type='hidden' name='id' value='".$row['id']."'/><input type='submit' name='submit-btn' value='View/Update Details' /><form></td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<div class="btn btn-info">Insert a new member</div>
<div class="btn btn-danger">Clear table</div>
</div>
</body>
</html>
Thanks for the help.
Replace
<form>
with
</form>
to end the form properly, otherwise it will be seen as only one form and the values of the last row will be used, since they are duplicated (one form contains all fields)
replace your edit buttom code.
echo "<td><form action='info.php' method='POST'><input type='hidden' name='id' value='".$row['id']."'/><input type='submit' name='submit-btn' value='View/Update Details' /><form></td></tr>";
with this code
echo '<a href="update.php/'. $row["id"].'"';
I am karthik, in my project i have one problem, i am getting error undefine index: template_id. I have searched more in net but i can't rectify this problem i have attached my code below, please guide me
if($fetquery["template_id"] == 5){
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template5-->
<input type="hidden" name="template5" value="template5">
<div class="fillContent" id="subscreen5">
<div class="mainTitle">
<h3>Fill Content - Template E</h3>
</div>
<input type="hidden" name="template5id" value="<?php echo $fetquery['temp5_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input type="text" class="fillTitleText" name="etemp5title"placeholder="Lorem Ipsum" value="<?php echo $fetquery['title']; ?>"><!-- Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template5banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp5_bannerimg" onchange="addtemplate5banner(this)" name="etemplate5bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp5banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div>
-->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Description</label> <textarea rows="4" name="etemp5desc" ><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php
}
if($fetquery["template_id"] == 6){
//echo "SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."";
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template6-->
<input type="hidden" name="template6" value="template6">
<div class="fillContent" id="subscreen6">
<div class="mainTitle">
<h3>Fill Content - Template F</h3>
</div>
<input type="hidden" name="template6id" value="<?php echo $fetquery['temp6_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input value="<?php echo $fetquery['title']; ?>" type="text" class="fillTitleText" name="etemplate6title" placeholder="Lorem Ipsum"> <!--Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template6banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp6_bannerimg" onchange="addtemplate6banner(this)" name="template6bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp6banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div> -->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Desription</label> <textarea rows="4" name="temp6desc"><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php } ?>
This code was in ajax page
Try to add a check before using it. And also check if it is defined or not. -
if (!empty($fetquery["template_id"]) && $fetquery["template_id"] == 5) { ...
Try to get 'id' and getting from url (?id=) it in case 1
Trying to get 'id' but not getting it in case 2
Please help me with this as it was a strange problem
Getting id in one case and not getting id on another case of the same page
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . '/config/config.inc.php');
include_once(TEMPLATES_ROOT_PATH . 'admin_header.php');
$pageTitle="New User";
include_once(CLASS_ROOT_PATH . '/AdminClass.php');
$adminObject = new AdminClass();
if(isset($_GET['id'])){
$editusers = $adminObject->getEditUsers($_GET['id']); //case1 - Getting id
}
if(isset($_POST['update'])){
$updateuserdata = array(
"user_name" => $_POST['username'],
"user_email" => $_POST['email'],
"user_phone" => $_POST['phone'],
"user_city" => $_POST['city'],
"role" => $_POST['role']
);
$editDetails = $adminObject->updateUsers($updateuserdata,$_GET['id']); //case2 - Not getting id (Please Help..)
echo "<script>";
echo "location.replace('/admin/users.php')";
echo "</script>";
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Edit User Details| </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Admin panel developed with the Bootstrap from Twitter.">
<meta name="author" content="travis">
<link href="<?php echo CSS_ROOT_PATH; ?>/admin_bootstrap.css" rel="stylesheet">
<link href="<?php echo CSS_ROOT_PATH; ?>/admin_style.css" rel="stylesheet">
<link href="<?php echo CSS_ROOT_PATH; ?>/admin_bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-wrench"></i> Administration</li>
<li class="active">Users</li>
<li>Roles</li>
<!--li>General</li>
<li>Users</li>
<li>Visitors</li-->
<li class="nav-header"><i class="icon-user"></i> Profile</li>
<li>My profile</li>
<li>Settings</li>
<li>Logout</li>
</ul>
</div>
</div>
<div class="span9">
<div class="row-fluid">
<div class="page-header">
<h1>Edit User Details</h1>
</div>
<form class="form-horizontal" method="post" action ="/admin/edit-user.php">
<fieldset>
<div class="control-group">
<label class="control-label" for="name">Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="name" name="username" value="<?php echo $editusers[0]['user_name'] ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">E-mail</label>
<div class="controls">
<input type="text" class="input-xlarge" id="email" name="email" value="<?php echo $editusers[0]['user_email'] ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="pnohe">Phone</label>
<div class="controls">
<input type="text" class="input-xlarge" id="phone" name="phone" value="<?php echo $editusers[0]['user_phone'] ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="city">City</label>
<div class="controls">
<input type="text" class="input-xlarge" id="city" name="city" value="<?php echo $editusers[0]['user_city'] ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="role">Role</label>
<div class="controls">
<select id="role" name="role">
<?php if($editusers[0]['role']==""){ ?>
<option value="Administrator">Administrator</option>
<option value="Moderator">Moderator</option>
<option value="User" selected>User</option>
<?php
}
?>
<?php if($editusers[0]['role']=="Administrator"){ ?>
<option value="Administrator">Administrator</option>
<option value="Moderator">Moderator</option>
<option value="User">User</option>
<?php
}
?>
<?php if($editusers[0]['role']=="Moderator"){ ?>
<option value="Moderator">Moderator</option>
<option value="Administrator">Administrator</option>
<option value="User">User</option>
<?php
}
?>
<?php if($editusers[0]['role']=="User"){ ?>
<option value="User">User</option>
<option value="Administrator">Administrator</option>
<option value="Moderator">Moderator</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-actions">
<button class="btn" id="submit" name="update" value="update">Update</button>
<a class="btn" href="users.php">Cancel</a>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<script src="<?php echo JS_ROOT_PATH; ?>/admin_jquery.js"></script>
<script src="<?php echo JS_ROOT_PATH; ?>/admin_bootstrap.min.js"></script>
<?php
include_once(TEMPLATES_ROOT_PATH . 'admin_footer.php');
?>
By not getting, do you mean that $editDetails is null, or that null is passed as the second argument to
$adminObject->updateUsers($updateuserdata,$_GET['id'])?
If the first case is the $_POST['update'] set?