I have a form, which have some input fields and also have some check box fields. If any one fill fields and select some checkbox and then submit. Then some data according submission shows on another div.
Now If same person again fill that fields after first submission and select checkbox and submit. Then some data according submission shows on div. But it replace old submission content. I need all submission content, on div including all old submission content.
My code is:
<form class="reservation-form mb-0" action="" method="post" novalidate autocomplete="off">
<input name="name1" class="form-control required " type="text" placeholder="Enter Name" aria-required="true" required>
<input name="age" class="form-control required " type="number" placeholder="Enter Age" aria-required="true" required>
<select required id="selectarea" class="form-control" name="selectgender">
<option>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<?php
$query1=mysql_query("select * from lab_location_package_rel where city_id='$selectcity1' AND area_id='$selectarea1' AND lab_id='$selectlab1'") or die (mysql_error());
while($value = mysql_fetch_array($query1)) {
$mrp=$value['mrp'];
$opp=$value['offer_price_perc'];
$package_id=$value['package_id'];
$per=$mrp*$opp/100;
$total=$mrp-$per;
$query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
$value2 = mysql_fetch_array($query2);
?>
<li class="list-group-item">
<div class="checkbox">
<input type="checkbox" id="checkbox" name="namec[]" value="<?php echo $value["id"]; ?>" />
<label for="checkbox">
<b>Package Name:</b> <?php $package_title1=$value2['package_title']; echo $package_title1;?> <br>
<b>MRP:</b> <strike><?php $mrp1=$value['mrp']; echo $mrp1; ?> </strike><br>
<b>Offer Price:</b> <?php $total1=$total; echo $total1; ?>
</label>
</div>
</li>
<?php }
?>
<input type="submit" class="pull-right btn btn-warning" value="Submit" name="submit">
</form>
Now After submission, for display code:
<div class="col-md-5">
<h5>Patient Details</h5>
<table class="table table-bordered">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
<th>Sex</th>
<th></th>
</tr>
<tr>
<?php if(isset($_POST["submit"])==true)
{ ?>
<td><?php echo $_POST['name1']; ?></td>
<td><?php echo $_POST['age']; ?></td>
<td><?php echo $_POST['selectgender']; ?></td>
<td>Update</td>
<?php } ?>
</tr>
</tbody>
</table>
<br /><br />
<h5>Package Details</h5>
<table class="table table-bordered">
<tbody>
<tr>
<th>Package</th>
<th>MRP</th>
<th>Offer Price</th>
<th></th>
</tr>
<tr>
<?php
extract($_POST);
foreach($_POST['namec'] as $selected){
$query1=mysql_query("select * from lab_location_package_rel where id='$selected'") or die (mysql_error());
while($value = mysql_fetch_array($query1)) {
$mrp=$value['mrp'];
$opp=$value['offer_price_perc'];
$package_id=$value['package_id'];
$per=$mrp*$opp/100;
$total=$mrp-$per;
$query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
$value2 = mysql_fetch_array($query2);
?>
<tr>
<td><?php echo $value2['package_title']; ?></td>
<td><strike><?php echo $value['mrp']; ?></strike></td>
<td><?php echo $total; ?></td>
<td>Delete</td>
</tr>
<?php
}
}
}
?>
</tr>
</tbody>
</table>
</div>
Related
I have the necessity where I need to put the data of a row inserted into an html form, where I can submit the data and insert it into a table.
The data is displayed into a page as a table, where I want to put an ADD button and transfer the content of the row in a form, filling the fields.
This is the code that shows the rows of data I want to add in the form
<?php
if ($result && $statement->rowCount() > 0) { ?>
<header class="w3-container w3-center w3-padding-12">
<h1>List</h1>
</header>
<h1><br></h1>
<a href="home.php" align='center'>Back to Home</a>
<h1><br></h1>
<table id="display-table" class="my_table" border='1' align='center'>
<thead>
<tr>
<th></th>
<th>Field 0</th>
<th>Field 1</th>
<th>Field 2</th>
<th>Field 3</th>
<th>Field 4</th>
<th>Field 5</th>
<th>Field 6</th>
<th>Field 7</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) { ?>
<tr>
<td>ADD</td>
<td><?php echo escape($row["Field0"]); ?></td>
<td><?php echo escape($row["Field1"]); ?></td>
<td><?php echo escape($row["Field2"]); ?></td>
<td><?php echo escape($row["Field3"]); ?></td>
<td><?php echo escape($row["Field4"]); ?></td>
<td><?php echo escape($row["Field5"]); ?></td>
<td><?php echo escape($row["Field6"]); ?></td>
<td><?php echo escape($row["Field7"]); ?></td>
<td><?php echo escape($row["Field8"]); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } else { ?>
As you can see, I added a field 'ADD' that brings you to the form page.
Here is the code of the form page
<label for="Field0">Field 0</label>
<input type="text" id="Field0" name="Field0" maxlength="60" required>
<label for="Field1">Field 1</label>
<select id="Field1" name="Field1">
<option value="SubField0">Field 1</option>
<option value="SubField1">Field 2</option>
<option value="SubField2">Field 3</option>
<option value="SubField3">Field 4</option>
</select>
<label for="Field2">Field2</label>
<input type="text" name="Citta" id="Citta">
<label for="Field3">Field 3</label>
<input type="text" name="Field3" id="Field3">
<label for="Field4">Field 4</label>
<input type="text" name="Field4" id="Field4">
<label for="Field5">Field 5</label>
<input type="text" name="Field5" id="Field5">
<label for="Field6">Field 6</label>
<input type="date" name="Field6" id="Field6">
<label for="Field7">Field 7</label>
<input type="date" id="Field7" name="Field7">
<label for="Field8">Field 8</label>
<input type="text" name="Field8" id="Field8">
<br><br>
<input type="submit" name="submit" value="Submit">
<br><br><br>
Back to Home<br><br>
</div>
</body>
</html>
<?php
if (isset($_POST['submit'])) {
require "../../../security/config.php";
require "../../../security/common.php";
try {
$connection = new PDO($dsn, $username, $password, $options);
$new_call = array(
"Field0" => $_POST['Field0'],
"Field1" => $_POST['Field1'],
"Field2" => $_POST['Field2'],
"Field3" => $_POST['Field3'],
"Field4" => $_POST['Field4'],
"Field5" => $_POST['Field5'],
"Field6" => $_POST['Field6'],
"Field7" => $_POST['Field7'],
"Field8" => $_POST['Field8'],
);
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"db.my_table",
implode(", ", array_keys($new_call)),
":" . implode(", :", array_keys($new_call))
);
$statement = $connection->prepare($sql);
$statement->execute($new_call);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
Can someone tell me how to edit my code in order to do what I have in mind?
One of my html forms is not POSTing data, the submit button respect the action attribute and redirect the page as spected BUT $_POST[] is empty for some reason. could sonebody help me find the issue here?
I already tried using html method POST and even ajax to process the form and submit the data, and theres no case. $_POST[] will allways stay empty (this is the only page that does that, I hava an exact copy of the form but without the GET method and it works fine...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="nocep-rules.css" rel="stylesheet" type="text/css">
<?php
session_start();
$link = mysqli_connect("localhost", "xxxx", "xxxx", "xxxxxx");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
<?php
if(!isset($_SESSION['logged'])){
header("location: /bubale/login.php");
}
?>
</head>
<body>
<div class="header">
<img class="logo" src="/bubale/img/logo1.png" alt="" />
<img class="foro-title" src="/bubale/img/loja_title.png" alt="" />
</div>
<div class="menu">
<nav class="site-nav">
<ul>
<li>HOME</li>
<li>LOJA</li>
<li>FORUM</li>
<li>CHECKOUT</li>
<li>SAIR</li>
</ul>
</nav>
</div>
<div class="info">
<table width="100%">
<tr>
<td width="20%">
<h2 class="text">USUÁRIO:</h2>
<?php echo $_SESSION['logged']; ?>
<h2 class="text2">PONTOS:</h2>
<?php
$sql5= "Select points from profile where user = '".$_SESSION['logged']."'";
$result5 = mysqli_query($link, $sql5);
if(mysqli_num_rows($result5)==1){
while($row5 = mysqli_fetch_assoc($result5)) {
echo $row5['points'];
}
}
?>
</td>
<td width="30%">
<?php
$sql2= "select * from bolsinhas where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result2 = mysqli_query($link, $sql2);
$count = mysqli_num_rows($result2);
?>
<h2 class="text">BOLSINHAS:</h2>
<?php echo $count; ?>
<h2 class="text2">PRODUTOS:</h2>
<?php
$sql3= "select * from fullsize where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result3 = mysqli_query($link, $sql3);
$count3 = mysqli_num_rows($result3);
echo $count3;
?>
</td>
<td>
<?php
if(!empty($_SESSION["shopping_cart"])) {
$cart_count = count(array_keys($_SESSION["shopping_cart"]));
}else{$cart_count = "0";}
?>
<img id="icon1" src="img/basket.png" title="Compras" ><span id = "count_wrapper"><a id="count">
<?php echo $cart_count; ?></a></span>
<img class="icon" src="img/sale.png" title="Promoção" alt="" >
<img class="icon" src="img/points.png" title="Fidelidade Buba'le" alt="" >
</td>
</table>
</div>
<h1 class="frete">FRETE:</h1>
<div class="wrapper_frete">
<?php
$rua1 = $_GET['1'];
$numero1 = $_GET['2'];
$apt1 = $_GET['3'];
$cep1 = $_GET['4'];
?>
<table id="forma_frete" width="100%">
<tbody>
<th>DADOS PESSOAIS</th>
<th>OOPS!!!</th>
<tr>
<form id="modform" method="POST" action="nocep2.php">
<td width="40%" class="td2">
<table id="nested" width="100%">
<tr>
<td id="td-nested-left" width="30%">
<label class="label-form" for="user">USUÁRIO:</label><br>
<label class="label-form" for="rua">RUA:</label><br>
<label class="label-form" for="numero">NÚMERO:</label><br>
<label class="label-form" for="apt">APT:</label><br>
<label class="label-form" for="cep">CEP:</label><br>
</td>
<td id="td-nested-right">
<input name="user" form="buttons" type="text" maxlenght="20" disabled value="<?php echo $_SESSION['logged']; ?>" /><br>
<input name="rua" form="buttons" type="text" value="<?php echo $rua1; ?>" /><br>
<input name="numero" form="buttons" type="text" value="<?php echo $numero1;?>" /><br>
<input name="apt" form="buttons" type="text" value="<?php echo $apt1; ?>" /><br>
<input name="cep" form="buttons" type="text" value="<?php echo $cep1;?>" />
</td>
</tr>
</table>
<input type="submit" class="refresh" value="ATUALIZAR">
</td>
</form>
<td id="td_mensage">
<h3 id="mensage">-irrelevant text-. </h3>
</td>
</tr>
<tr>
<td id="td_ob" colspan="2">
<h3 id="comentario">OBSERVAÇAÕ:</h3>
<textarea form="buttons" name="observacion" id="text_ob" placeholder="Deixe aqui sua observaçaõ..."></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<h1 class="frete">SUA COMPRA:</h1>
<?php
if(isset($_SESSION["shopping_cart"])){
$total_price = 0;
?>
<?php } ?>
<table class="table">
<tbody>
<tr>
<th></th>
<th>PRODUTO</th>
<th>QUANTIDADE</th>
<th>VALOR UNITARIO</th>
<th>VALOR TOTAL</th>
</tr>
<?php
foreach ($_SESSION["shopping_cart"] as $product){
?>
<tr>
<td id="imgtd"><img src='<?php echo $product["image"]; ?>' width="90" height="80" /></td>
<td><?php echo $product["name"]; ?><br />
<form method='post' action=''>
<input type='hidden' name='code' value="<?php echo $product["code"]; ?>" />
</form></td>
<td><form method='post' action=''>
<input type='hidden' name='code2' value="<?php echo $product["code"]; ?>" />
<?php echo $product["quantity"];?>
</form></td>
<td><?php echo "R$".$product["price"]; ?></td>
<td><?php echo "R$".$product["price"]*$product["quantity"]; ?></td>
</tr>
<?php
$total_price += ($product["price"]*$product["quantity"]);
}
?>
<tr>
<td class="td_tot" colspan="5" align="right"><strong id="total">TOTAL: <?php echo "R$".$total_price; ?></strong></td>
</tr>
</tbody>
</table>
<form method="post" action="contact-venta.php" id="buttons">
<?php
?>
<input type="hidden" name="compras" value="<?php echo print_r($_SESSION["shopping_cart"], TRUE); ?>"/>
<input type="hidden" name="total" value="<?php echo $total_price; ?>">
<input type="submit" id="submit" value="ENVIAR">
</form>
<?php mysqli_close($link); ?>
</body>
</html>
the issue is with the first submit (the one with the value ACTUALIZAR), the form will go to nocep2.php BUT $_POST[] will remain empty .... I posted the entire page just in case there is an issue I'm not seeing....
Your HTML is rather confused.
Firstly, <form> is not a valid element in <tr>. The browser is rendering them outside the table, and separate from your <input>. Move your form tags inside the <td>, or move them outside the <table>
Eg
<table>
<tr>
<td>
<form method="POST">
<input type="text" name="inputName">
<input type="submit">
</form>
</td>
</tr>
</table>
Or, if you need to spread your form over several cells:
<form method="POST">
<table>
<tr>
<td>
<input type="text" name="inputName1">
</td>
<td>
<input type="text" name="inputName2">
</td>
<td>
<input type="submit">
</td>
</tr>
</table>
</form>
Secondly, you're creating a number of <input> elements of type "hidden", each with their own form tags, so they are each part of a different form. Reorder your code so that the hidden elements appear within the same <form> as the rest of your <input>
I got stuck with my edit/modify button made in PHP from mysqli database.
I can't make all 3 rows work together, the only one that works is the date, the others don't modify and I don't even get any error or something.
The primary key is codr.
Any clue?
This is the index.php
<?php
include 'header.php';
?>
<div class="head"></div>
<div class="cont">
<?php
$conn= mysqli_connect("localhost","root", "", "registration");
$sql="SELECT * FROM fiser";
$result=mysqli_query($conn, $sql);
$queryResults= mysqli_num_rows($result);
if($queryResults > 0) {
while ($row = mysqli_fetch_assoc($result)) { echo"
<table border=1 bgcolor=#b3ccff>
<tr>
<th>Numarul fisei de retur</th>
<th>Numarul comenzii</th>
<th>Data inregistrarii fisei de retur</th>
<th>Motivul returului </th>
<th colspan=2><center> Actiune </th>
</tr>
<tr>
<td><p> ".$row['codr']." </p> </td>
<td><p> ".$row['codc']." </p> </td>
<td><p> " .$row['datar']." </p></td>
<td><p> " .$row['motivr']." </td>
<td><a href='edit.php?edit=$row[codr] '> edit </a> </td>
</tr> "; }} ?>
</div>
This is edit.php
<?php
include('header.php') ;?>
<?php
if (isset($_GET['edit']))
{
$codr=$_GET['edit'];
$sql="SELECT * FROM fiser WHERE codr='$codr'";
$res= mysqli_query($conn, $sql);
$row= mysqli_fetch_array($res);
}
if(isset($_POST['newComanda']) && isset($_POST['newName']) && isset($_POST['newData']))
{
$newName=$_POST['newName'];
$newComanda=$_POST['newComanda'];
$newData=$_POST['newData'];
$codr=$_POST['codr'];
$sql="UPDATE fiser SET codc='$newComanda' && motivr='$newName' && datar='$newData' WHERE codr='$codr'";
$res=mysqli_query($conn,$sql) or die("Could not update".mysqli_error($conn));
echo "<meta http-equiv='refresh' content='0;url=form.php'>";
}
?>
<form action="edit.php" method="POST">
Cod comanda : <input type="text" name="newComanda" value="<?php echo $row['codc']; ?>"><br>
Motiv : <input type="text" name="newName" value="<?php echo $row['motivr']; ?>"><br>
Data : <input type="date" name="newData" value="<?php echo $row['datar']; ?>"><br>
<input type="hidden" name="codr" value="<?php echo $row[0]; ?>">
<input type="submit" value="Update">
</form>
I am doing a registration form where i am also saving image to database, well that image is being stored in LONGBLOB format. I am able to add and view all the data accept the image part.
Here is my product_register.php code:
<form role="form" method="post" action="product_register.php">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Product Name" name="product_name" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Product Code" name="product_code" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Product Image" name="product_image" type="file" value="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Purchase Date" name="date" type="date" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Time Guarantee" name="time_guarantee" type="text" autofocus>
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="submit" name="submit" >
</fieldset>
</form>
<?php
include("db_conection.php");//make connection here
//mysql_close();
if(isset($_POST['submit']))
{
$usern = $_SESSION['sess_username'];
$product_name = $_POST['product_name'];
$product_code = $_POST['product_code'];
$product_image = $_POS['product_image'];
$date = $_POST['date'];
$time_guarantee = $_POST['time_guarantee'];
$insert_user = "insert into product (product_name,product_code,product_image,date,time_guarantee,usern) VALUE ('$product_name','$product_code','$product_image','$date','$time_guarantee','$usern')";
if(mysqli_query($dbcon,$insert_user))
// $result = mysql_query($insert_user);
{
echo "<script type='text/javascript'>alert('Product added successfully !!!')</script>";
// echo"<script>window.open('product_register.php','_self')</script>";
// mysql_close();
}
}
?>
Here is the code to view it view_product.php code:
<table class="table table-bordered table-hover table-striped" style="table-layout: fixed">
<thead>
<tr>
<!-- <th>User Id</th> -->
<th>Product Name</th>
<th>Product Code</th>
<th>Product Image</th>
<th>Date of Purchase</th>
<th>Time Guarantee</th>
<!-- <th>Delete User</th> -->
</tr>
</thead>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("gmgmt") or die(mysql_error());
// $view_users_query="select * from users WHERE role='user'"; //select query for viewing users.
// $view_users_query="select * from users WHERE role='admin'"; //select query for viewing users.
$view_users_query="select * from 'product' WHERE 'usern' = 'demo'"; //select query for viewing users.
// $run=mysql_query($view_users_query);//here run the sql query. // '".$_SESSION['userid']."'
$check = mysql_query("SELECT * FROM product WHERE usern = '".$_SESSION['sess_username']."' ") or die(mysql_error());
while($row=mysql_fetch_array($check)) //while look to fetch the result and store in a array $row.
{
$id=$row[0];
$product_name=$row[1];
$product_code=$row[2];
$product_image=$row[3];
$date=$row[4];
$time_guarantee=$row[5];
// $usern=$row[6];
?>
<tr>
<!--here showing results in the table -->
<!-- <td><?php echo $id; ?></td> -->
<td><?php echo $product_name; ?></td>
<td><?php echo $product_code; ?></td>
<td><?php echo "<img src='php/imgView.php?imgId=".$product_image."' />"; ?></td>
<td><?php echo $date; ?></td>
<td><?php echo $time_guarantee; ?></td>
<!-- <td><button class="btn btn-danger">Delete</button></td> -->
</tr>
<?php } ?>
</table>
I searched a lot but I didn't find a code or method that suits my needs.
echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['imageContent'] ) . '" />';
Use the above code to display you image store in mysql database. Hope this will help you
Hi guys i coded a search php in custom page for my site and want do search job in same page (i don't want send data to action page).
but i have problem i don't know why this is not work pleas can some one tell me what's problem and what is the current one?!
Thank you.
<div class="row-fluid">
<div class="page-header">
<h1>Search Users: </h1>
</div>
<center>
<h2>Find user(s)</h2>
<form name="search" method="post" action="">
Seach for: <input type="text" name="find" /> with
<Select NAME="field">
<Option VALUE="user_id">User ID</option>
<Option VALUE="username">Username</option>
<Option VALUE="serialnumber">SerialNumber</option>
<Option VALUE="ip_address">IP Address</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" class="btn btn-success" style="vertical-align: super;" />
</form>
<span><?php echo $error; ?></span>
</center>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>E-mail</th>
<th>IP</th>
<th>serialnumber</th>
<th>Actions</th>
</tr>
</thead>
<?php
if (isset($_POST['submit'])) {
if (empty($_POST['find']) || empty($_POST['field'])) {
$error = "Pleas choice options";
}
else
{
$find=$_POST['find'];
$value=$_POST['field'];
$sql = "SELECT * FROM login_log WHERE '$value' = '$find'";
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result)) {
?>
<tbody>
<tr class="pending-user">
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['ip_address']; ?></td>
<td><?php echo $row['serialnumber']; ?></td>
<td>Ban User</td>
</tr>
</tbody>
<?php
}
}
}
?>
</table>
</div>
$_POST will contain elements from the form where you use the name= attribute for your form fields. $_POST['submit'] won't exist unless you have name="submit" for one of the fields or buttons. Do a var_dump($_POST) to see what values are being sent back to the form.
Change isset($_POST['submit']) to isset($_POST['search']
See a tutorial on how to use forms.