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.
Related
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 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>
i want to make a cart and my product is pizza.
so i'm listing all the menu to the table, and add a button to submit menu to cart.
here's my index.php
<?php
require("connect.php");
$result = mysqli_query($con,'select * from menu');
?>
<form action="cart.php" method="get">
<table border="1" style="width:100%">
<tr>
<th>Pizza Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Buy</th>
</tr>
<?php while($product = mysqli_fetch_object($result)){ ?>
<tr>
<td><?php echo $product->nama_menu; ?></td>
<td><?php echo $product->harga_menu; ?></td>
<td><input type="number" name="quantity" min="1" max="20"></td>
<td><button type="submit" name="id" value="<?php echo $product->id_menu; ?>">Add To Cart</button></td>
</tr>
<?php } ?>
</table>
</form>
But when i pressed the button "Add To Cart", it sends all the quantity from the menu listing and can't be read in my cart.php
can anyone help me how to get the right quantity value when i pressed the button add to cart.
Make separate form for each of the item. Try below code.
<?php
require("connect.php");
$result = mysqli_query($con,'select * from menu');
?>
<table border="1" style="width:100%">
<tr>
<th>Pizza Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Buy</th>
</tr>
<?php while($product = mysqli_fetch_object($result)){ ?>
<form action="cart.php" method="get">
<tr>
<td><?php echo $product->nama_menu; ?></td>
<td><?php echo $product->harga_menu; ?></td>
<td><input type="number" name="quantity" min="1" max="20"></td>
<td><button type="submit" name="id" value="<?php echo $product->id_menu; ?>">Add To Cart</button></td>
</tr>
</form>
<?php } ?>
</table>
Try to use array in name then submit it will give you seperate quantity.
<td><input type="number" name="quantity[<?php echo $product->nama_menu; ?>]" min="1" max="20">
Output:
quantity['pizza1'] = 10
quantity['pizza2'] = 20
....
Another Option is use dynamic name for number.
<td><input type="number" name="quantity_<?php echo $product->nama_menu; ?>" min="1" max="20">
Output:
quantity_pizza1 = 10
quantity_pizza2 = 20
....
I am new in php, I just starting learn php and have some problems.
In admin panel I have some form for adding info, after that in output I have radio buttons for selecting which row show into website. The problem is in update function the query is ok but it doesn't work, and I need you help.
thanks.
submit if.
if(isset($_POST['update_info'])){
$selected_info=$_POST['selected'];
$selected_id = $_POST['id'];
updateHomeInfo($selected_info, $selected_id);
}
output added rows.
<div class="home-output">
<form action="/admin/" method="post">
<table class="table table-hover">
<thead>
<tr>
<td>#</td>
<td>slected</td>
<td>title</td>
<td>descriptiom</td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<?php foreach($homeInfo as $row) { ?>
<tr>
<td><?php echo $row['id']; ?><input type="hidden" name="id" value="<?php echo $row['id']; ?>"></td>
<td><input type="radio" name="selected" value="home-info" <?php if($row['selected'] == 1) echo "checked"; ?> /></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['description']; ?></td>
<td></td>
<td></td>
</tr>
<?php } ?>
<tr>
<td>
<input type="submit" class="btn btn-default" name="clear_info" value="delete all">
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type="submit" class="btn btn-default" name="update_info" value="update">
</td>
</tr>
</tbody>
</table>
</form>
</div>
and update function.
function updateHomeInfo($selected_info, $selected_id) {
global $db;
$db->exec("UPDATE home SET selected = '$selected_info' where id = '$selected_id'");
}
All your hidden inputs have the same name; they'll all be submitted, and the value of $_POST['id'] will just be the last one, not the one next to the selected radio button. And all the radio buttons have the same value as well.
You should put the ID into the value of the radio button. You only need one copy of the hidden input, and it can contain the selected info.
<form action="/admin/" method="post">
<input type="hidden" name="selected" value="home-info">
<table class="table table-hover">
...
<td><?php echo $row['id']; ?>
<td><input type="radio" name="id" value="<?php echo $row['id']; ?>" <?php if($row['selected'] == 1) echo "checked"; ?> /></td>
...
Actually, it seems like you don't need the selected input at all, if selected is a boolean. It should just be:
function updateHomeInfo($selected_id) {
$db->exec("UPDATE home SET selected = (id = '$selected_id')");
}
This will set selected to 1 for the selected ID, and 0 for all the other IDs.
Im having a page that shows monthly subscriptions of a user which is created using codeigniter. what i want to do is when a the user clicks on make payment pass the values in the hidden files to the controller.
<?php echo form_open('options/done');?>
<table class="tables">
<thead>
<tr>
<th>Ref Code</th>
<th>Month</th>
<th>Year</th>
<th>action/th>
</tr>
</thead>
<tbody>
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];?>
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<tr>
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo form_close();?>
so when someone hits the submit button how can i pass only the hidden values which are relevant to that table row?
add form just inside the <tr> elements inside your loop (see below with your code)
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];
?>
<tr>
<form action="target.php" method="post" name="formName_<?php echo $s;?>" >
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</form>
</tr>
<?php endforeach; ?>