Retrieve multiple row value with dynamic id of html table using php - php

I have a html table with multiple rows with dynamic Id and name assigned. I want to retrieve the rows values in php. When I am doing the same, it is showing: undefined index error. The code is as below, pls help where I am wrong
<?php
if(isset($_POST["hdnsubmitted"])
{
for ($i=0;$i<6;$i++)
{
$curr_status=$_POST['curr_status'.$i]; echo $curr_status;
}
$Status= "Status Updated";
}
?>
<form method="post" action="targetpage">
<table class="freeze-table">
<thead>
<tr >
<th class="col-id-no fixed-header" >CURRENT STATUS</th>
<th class="col-id-no fixed-header" >PENDING INPUTS</th>
</tr>
</thead>
<?php
$query="SELECT * FROM `status` WHERE 1";
$sql=mysqli_query($conn,$query);
$i=0;
while ($row=mysqli_fetch_array($sql)){
echo "<tr>
<td name='Curr_status'".$i."><div contenteditable> ".$row['CURRENT_STATUS']." </td>
<td name='Pending_Inputs'".$i."><div contenteditable> ".$row['PENDING_INPUTS']." </td>";
$i=$i+1;
}
?>
</tr>
</table>
<br>
<button type="submit" name="btn_Update" class="btn_Update">Update</button>
<p style="color:black;text-align: center"> <?php echo $Status; ?></p>
</form>

You don't have any form. You have a table and table contents do not sent to php.
You must use a form with fields. Each field must have a name.
In below simplest example: method is post so your form content will be in $_POST. In targetpage.php page, try var_dump($_POST) to see the result after you submit the form.
You'll see $_POST is an array with these keys: email, name, submit.
form.php // php page that has the form
<form action="targetpage.php" method="post">
<div class="form-example">
<label for="name">Enter your name: </label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-example">
<label for="email">Enter your email: </label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-example">
<input type="submit" value="Subscribe!">
</div>
</form>

Related

unable to store my all retrieve the data from the Mysql table to my new html form.

Here i am facing a problem with the while loop.. (i think) unable to store my all retrieve the data from Mysql table to my html form.
the first row is only getting posted and the rest of the rows are not posting due to same name element getting repeated from the while loop,
Here the $_POST['mechanic_name']; one time i'm using.. any problem with this..
because this is not in a while loop, ore if you think any other problems with the code below pls advice
<?php
include("db_conection.php");
$view_users_query="select * from mechanic";//select query for viewing users.
$run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
{
$mechanic_ID=$row[0];
$mechanic_name=$row[1];
?>
<tr>
<td>
<input name="mechanic_ID" type="text" value="<?php echo $mechanic_ID; ?>">
</td>
<td>
<input name="mechanic_name" type="text" value="<?php echo $mechanic_name; ?>">
</td>
</tr>
<!--* For save php script*-->
<?php
include("db_conection.php");//make connection here
if(isset($_POST['register']))
{
$mechanic_ID=$_POST['mechanic_ID'];//here getting result from the post array after submitting the form.
$mechanic_name=$_POST['mechanic_name'];//same
$month=$_POST['month'];//same
if($mechanic_name=='')
{
//javascript use for input checking
echo"<script>alert('Please enter the name')</script>";
exit();//this use if first is not work then other will not show
}
//insert the user into the database.
$insert_schedule="insert into schedule (mechanic_ID,mechanic_Name,) VALUE ('$mechanic_ID','$mechanic_name'[enter image description here][1])";
if(mysqli_query($dbcon,$insert_schedule))
{
echo"<script>window.open('index.html','_self')</script>";
}
}
plz help me...!`
<div>
<form role="form" method="post" action="schedule.php">
<table class="table table table-inverse table-hover">
<fieldset>
<div>
<input class="form-control" placeholder="Username" name="month" type="Month" value="January">
</div>
<thead class="thead-inverse">
<tr>
<th>Mechanic Id</th>
<th>Mechanic Name</th>
<th>Woking Day Selection</th>
<th>Delete User</th>
</tr>
</thead>
<?php
include("db_conection.php");
$view_users_query="select * from mechanic";//select query for viewing users.
$run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
{
$mechanic_ID=$row[0];
$mechanic_name=$row[1];
?>
<tr>
<td>
<input name="mechanic_ID" type="text" value="<?php echo $mechanic_ID; ?>">
</td>
<td>
<input name="mechanic_name" type="text" value="<?php echo $mechanic_name; ?>">
</td>
<td>
<div class="weekDays-selector">
<input type="checkbox" name="Sun" id="weekday-sun" class="weekday" />
<label for="weekday-sun">S</label>
<input type="checkbox" name="Mon" id="weekday-mon" class="weekday" />
<label for="weekday-mon">M</label>
<input type="checkbox" name="Tue" id="weekday-tue" class="weekday" />
<label for="weekday-tue">T</label>
<input type="checkbox" name="Wed" id="weekday-wed" class="weekday" />
<label for="weekday-wed">W</label>
<input type="checkbox" name="Thu" id="weekday-thu" class="weekday" />
<label for="weekday-thu">T</label>
<input type="checkbox" name="Fri" id="weekday-fri" class="weekday" />
<label for="weekday-fri">F</label>
<input type="checkbox" name="Sat" id="weekday-sat" class="weekday" />
<label for="weekday-sat">S</label>
</div>
</td>
<td>
<!--button-->
<input class="btn btn-lg btn-success btn-block" type="submit" value="register" name="register" >
</td>
</tr>
</fieldset>
<?php } ?>
</table>
</form>
</div>
<?php
include("db_conection.php");//make connection here
if(isset($_POST['register']))
{
$mechanic_ID=$_POST['mechanic_ID'];//here getting result from the post array after submitting the form.
$mechanic_name=$_POST['mechanic_name'];//same
$month=$_POST['month'];//same
$Sun=$_POST['Sun'];//same
$Mon=$_POST['Mon'];//same
$Tue=$_POST['Tue'];//same
$Wed=$_POST['Wed'];//same
$Thu=$_POST['Thu'];//same
$Fri=$_POST['Fri'];//same
$Sat=$_POST['Sat'];//same
if($mechanic_name=='')
{
//javascript use for input checking
echo"<script>alert('Please enter the name')</script>";
exit();//this use if first is not work then other will not show
}
//insert the user into the database.
$insert_schedule="insert into schedule (mechanic_ID,mechanic_Name,month,Sun,Mon,Tue,Wed,Thu,Fri,Sat) VALUE ('$mechanic_ID','$mechanic_name','$month','$Sun','$Mon','$Tue','$Wed','$Thu','$Fri','$Sat')";
if(mysqli_query($dbcon,$insert_schedule))
{
echo"<script>window.open('index.html','_self')</script>";
}
}
?>
ok
your text input have same static name
you shuld give it an array name if you want to save it like :
<input type="text" name="mechanic_ID[]" value="first_one" />
<input type="text" name="mechanic_ID[]" value="second_one" />
and when get data
$mechanic_ids = $_POST['mechanic_ID'];
// this give you data in array ('first_one','second_one')
can resume
foreach($mechanic_ids as $mechanic_id){
// do some thing in this one
}
here good example about arrays form html and php
here is the things is mechanic table whole data (mechsanic_ID , Mechanic_name) able to retrieve, it's showing all the data; because of while loop, But when register it the very first row only able to posted and the rest of the rows are not postinginterface look like this.

i have include html form element with php but that does not post

hi i use a form and i add a few textarea my form with php. But i click submit buton it does not post. Why? is there any problem?
<form onsubmit="return form_kontrol()" name="form1" class="block-content form" id="simple_form" method="POST" action="<?php echo $editFormAction; ?>">
<div id="kodlar">
< ? php
$i=1;
mysql_select_db($database_verisi_tabanisi, $verisi_tabanisi);
$query_sipsa = "SELECT * FROM sifreler where kayit_id=".$_GET['id'];
$sipsa = mysql_query($query_sipsa, $verisi_tabanisi) or die(mysql_error());
$row_sipsa = mysql_fetch_array($sipsa);
$totalRows_sipsa=mysql_num_rows($sipsa);
do{
echo "<p style=\"display:inline;\" id=\"p".$i."\">
<label for=\"sifre\">Kod ".$i.":</label>
<textarea disabled name=\"kod".$i."\" id=\"kod".$i."\" cols=\"70\" rows=\"3\" style=\"margin-left:10px;\">".$row_sipsa['sifre']."</textarea>
<img src=\"images/icons/fugue/cross-circle.png\" width=\"16\" height=\"16\">
<p>";
$i++;
} while($row_sipsa = mysql_fetch_array($sipsa));
? >
</div>
this is php code and everything is normal.
<table width="461px">
<tr> <td width="35%"><label for="kullanici">İsim Soyisim:</label></td>
<td width="65%"><input name="isim" type="text" id="isim" class="full-width" style="width:300px;" value="<?php echo $row_sipsa['isim_soyisim'];?>"></td>
</tr>
</table>
<br> <br>
<table width="461px">
<tr> <td width="35%"><label for="sifre">Telefon:</label></td>
<td width="65%"><input name="tel" type="text" id="tel" class="full-width" style="width:300px;" value="<?php echo $row_sipsa['telefon'];?>"></td>
</tr>
</table>
Disabled form element won't post to other page.
If you want make textarea disabled the you have below options:
Make them readonly by adding the readonly property to the element.
disable them in CSS/JavaScript. Color it like it's disabled, and
don't allow editing with JavaScript
Leave it disabled, and remove the disabled on submit.
Choose anyone. :-)

two forms conflict with each other

I have placed two forms on one page. Bothe forms work fine separately but when they are placed on one page at the same time they conflict with each other. Here are both forms:
Contact Form:
<form name="contactform" id="contactform" method="post" action="#targetAnchorPage2">
<table>
<?php
if (isset($_POST["name"])){
?>
<tr>
<td colspan="2" class="error">
<?php
require_once("contact_send.php");
?>
</td>
</tr>
<?php
}
?>
<tr><td><label for="name" class="<?=$name_class?>">name:</label></td><td><input type="text" name="name" maxlength="50" value="<?=$name?>"></td></tr>
<tr><td><label for="email" class="<?=$emailaddress_class?>">email:</label></td><td><input type="text" name="email" maxlength="80" value="<?=$emailaddress?>"></td></tr>
<tr><td colspan="2"><label id="tworows" for="message" class="<?=$message_class?>">your message:</label></td></tr><tr><td colspan="2"><textarea name="message" cols="22" rows="6" value="<?=$message_class?>"></textarea>
</td></tr>
<tr>
<td colspan="2" style="text-align:center"><br /><input class="button" type="submit" value="">
</td>
</tr>
</table>
</form>
Subscribe Form:
<form name="subscribeform" id="subscribeform" method="post" action="#targetAnchorPage3">
<table>
<?php
if (isset($_POST["name"])){
?>
<tr>
<td colspan="2" class="error">
<?php
require_once("subscribe_send.php");
?>
</td>
</tr>
<?php
}
?>
<tr><td><label for="name" class="<?=$name_class?>">name:</label></td><td><input type="text" name="name" maxlength="50" value="<?=$name?>"></td></tr>
<tr><td><label for="email" class="<?=$emailaddress_class?>">email:</label></td><td><input type="text" name="email" maxlength="80" value="<?=$emailaddress?>"></td></tr>
<tr>
<td colspan="2" style="text-align:center"><br /><input class="button" type="submit" value="">
</td>
</tr>
</table>
</form>
How can this be solved? Is it caused by the "required_once" command?
I am guessing that since you are showing the required files based on the same criteria isset($_POST['name']) and since both forms have the name field you end up showing the code in both requires regardless of which form is submitted. You should simply change the form field names on on of the forms such that they are different.
Both forms have the same action attribute, they both point back to the same page (note that the hash is not sent to the server). As they both have a field called name and you are checking for that, both actions get executed regardless of which form was sent in.
You can do either:
use different scripts / form processors (don't post back to the same page)
use a different check for each form, for example by adding a hidden input that will allow you to distinguish between the forms.
Add
formaction="Your_URL"
Attribut in Button

Submitting form from different <div> HTML

i have problem with submitting a form using 2 defferent div(tabs). I want to submit all the value from this form.. but when i submit, the value that i receive only from (div class="tab1") not from div class="tab2". how can i submit all the value even using different div
page.php
<div class="tab1">
<h2>Basic Information</h2>
<form name="pages_details" method="post" action="pages/save_pages.php">
<table>
<tr>
<td>Name:</td>
<td><input name="name" type="text" ></input></td>
</tr>
<tr>
<td>Order:</td>
<td><input name="ord" type="text"></input></td>
</tr>
</table>
</div>
<div class="tab2">
<h2>Additional Information</h2>
<table>
<tr>
<td>Special:</td>
<td><input name="special" type="text" ></input></td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title" type="text"></input></td>
</tr>
</table>
</div>
<input type="submit" name="save" value="save">
</form>
save_pages.php
<?php
$name = $_REQUEST['name'];
$ord = $_REQUEST['ord'];
$special = $_REQUEST['special'];
$title = $_REQUEST['title'];
echo $name;
echo $ord;
echo $special;
echo $title;
?>
Try to make sure you close tags in the right order.
Structuring code like this can cause some weird bugs.
Not right:
<div>
<form>
</div>
</form>
So you might want to do it like this.
<form>
<div>
</div>
</form>
I would suggest to use jquery ajax to submit the form based on your case.
For example:
var datas = $(form).serialize();
$.post("pages/save_pages.php", datas, function(){
});
Referring:
post - http://api.jquery.com/jQuery.post/
serialize - http://api.jquery.com/serialize/

Undefined variable: POST - PHP and MySQL

I've got a form like this:
<form name="htmlform" method="post" action="script/gen.php?postData">
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="customer">Customer:</label>
</td>
<td valign="top">
<input type="text" name="customer" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="nol">Number of licences: </label>
</td>
<td valign="top">
<input type="text" name="nol" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<form method="post" id="submit" action="script/gen.php">
<input type="button" onClick="getKey()"; value="Generate key"/>
</td>
</tr>
<div id="innhold">
<h4>Licence Key: </h>
</div>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
The codelines of interest is:
<input type="text" name="nol" maxlength="50" size="30">
and
<input type="text" name="customer" maxlength="50" size="30">
I try to write this information to a database like this:
function postData($key1) {
//just to check if the key is equal to the one thats posted to the user
//echo '<h5>From postData' . $key1 . '</h5>';
/*echo '<script type="text/javascript"> alert("The order has been submitted successfully");
location = "/Webpanel/index.html";
</script>';*/
$customerVar = $POST['customer'];
$nolVar = $POST['nol'];
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("licencedatabase");
$query_add = "INSERT INTO licence (`customer_name`,`licence_count`) VALUES ('$customerVar','$nolVar')";
$query_exec = mysql_query($query_add) or die(mysql_error());
mysql_close();
}
But I keep getting the error:
Undefined variable: POST
How can I accomplish this? Thanks in advance.
Its $_POST not $POST.
$customerVar = $_POST['customer'];
$nolVar = $_POST['nol'];
That's because it's called $_POST.
Try using $_POST instead of $POST
to access the superglobal POST use $_POST not $POST
All PHP superglobals (such as those for GET and POST) are prefixed with an underscore, so: $POST should be $_POST.
Have a look here for more information about the available superglobals in PHP:
http://php.net/manual/en/language.variables.superglobals.php
Try using $_POST instead of $POST
Check following example:
The predefined $_POST variable is used to collect values from a form sent with method="post".
Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Example:
<form action="submitform.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
When the user clicks the "Submit" button, the URL will look like this: http://localhost/submitform.php
The "submitform.php" file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_POST array):
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
might you will understand clearly.

Categories