I've done a search related to 'update statement using form'.
Lots of post showed an update function using a form using isset
if(isset($_POST["submit"])) { //process } else { //show form }
Does this mean that it is not possible to do update using this?
if($_SERVER["REQUEST_METHOD"] == "POST") { //process } else { //show form }
It seems so cause my update function doesn't work.
Solved : It works now. I added
<input type="hidden" name="contact_id" value="<?php echo $row["contact_id"]; ?>" />
before
<input type="submit" name="submit" value="Submit" />
in the form
<form method="post" action="update.php">
Username: <input type="text" name="contact_name" value="<?php echo $row["contact_name"]; ?>" />
Email: <input type="text" name="contact_number" value="<?php echo $row["contact_number"]; ?>" />
<input type="hidden" name="contact_id" value="<?php echo $row["contact_id"]; ?>" />
<input type="submit" name="submit" value="Submit" />
</form>
bith ways should work.
But what you should do first is :
var_dump($_POST);
to make sure there is anything in the $_POST var before you do the 1st option.
I don't know if REQUEST_METHOD is always in uppercase. To test this, use strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' and see if it works.
Related
I have a form with 3 selections, and I want the form to replace the selected text with the name entered when submitted. So if the user enters their name as Josh, and picks 'King', I want the form to update itself and instead of having King it would say Josh which would no longer be a choice, and then have the other two characters below for someone else to pick from. This is a PHP document, but the data is in a HMTL form of course.
I was reading something about hidden forms, but was not sure how to implement them here. Does anyone have any suggestions?
<form method="get" action="">
Your Name: <input type="text" name="name" />
<br/>
<input type="radio" name="character" value="King"> King<br>
<input type="radio" name="character" value="Queen"> Queen<br>
<input type="radio" name="character" value="Prince"> Prince <br>
<input type="submit" value="Submit" />
Are you looking to do something like this?
You can do it by using php conditions and hidden fields.
Save the file with the name "form.php" then run it and tell me if it does the trick ;)
<form method="post" action="form.php">
Your Name: <input type="text" name="name" />
<br/>
<?php if((isset ($_POST['name-1']) || isset($_POST['name'])) && (isset ($_POST['character-1']) && $_POST['character-1']=='King'))
{
$name=isset($_POST['name-1'])?$_POST['name-1']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-1" value="'.$name.'"/><input type="hidden" name="character-1" value="'. $_POST['character-1'].'"/>';
}
else {?>
<input type="radio" name="character-1" value="King"> King<br>
<?php } ?>
<?php if((isset ($_POST['name-2']) || isset($_POST['name'])) && (isset ($_POST['character-2']) && $_POST['character-2']=='Queen'))
{
$name=isset($_POST['name-2'])?$_POST['name-2']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-2" value="'.$name.'"/><input type="hidden" name="character-2" value="'. $_POST['character-2'].'"/>';
}
else {?>
<input type="radio" name="character-2" value="Queen"> Queen<br>
<?php } ?>
<?php if((isset ($_POST['name-3']) || isset($_POST['name'])) && (isset ($_POST['character-3']) && $_POST['character-3']=='Prince'))
{
$name=isset($_POST['name-3'])?$_POST['name-3']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-3" value="'.$name.'"/><input type="hidden" name="character-3" value="'. $_POST['character-3'].'"/>';
}
else {?>
<input type="radio" name="character-3" value="Prince"> Prince <br>
<?php } ?>
<input type="submit" value="Submit" />
</form>
I am currently making a report error form that has 4 fields:
Job ID $jobid
Part ID part_id
Machine
Note
The user clicks on a table corresponding the their work and are brought to a new page with a url that has variable. At the moment all the fields are empty however I want the fields to be populated automatically except for notes.
Current Model
Link to report error form:
$EM_html = ''.$tick.'
Report error form:
<form action="" method="post">
Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
Machine Code: <input type="text" name="machCode"><br>
Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
Example URL
http://sra-pstest/report_error_form.php?JobID=KANBAN16-09-04-01&Machine=EM&PartID=124047
How do "extract" the information out of the url (JobID, Machine, PartID) and automatically fill out the form?
You can use $_GET
<?php
if(isset($_GET))
{
foreach($_GET as $key=>$value)
{
$$key=$value;
}
echo $JobID."<br>".$Machine."<br>".$PartID;
}
?>
Please try this
<?php
$jobid = #$_REQUEST['JobID'];
$part_id = #$_REQUEST['PartID'];
$machCode = #$_REQUEST['Machine'];
?>
<form action="" method="post">
Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
Machine Code: <input type="text" name="machCode"><br>
Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
You use $_GET Method like this code
<?php
$jobid=$part_id=$machine="";
if(isset($_GET['JobID']))
{
$jobid= $_GET['JobID'];
}
if(isset($_GET['Machine']))
{
$machine= $_GET['Machine'];
}
if(isset($_GET['PartID']))
{
$part_id= $_GET['PartID'];
}
?>
<form action="" method="post">
<?php $jobNumber = isset($_GET['JobID']) ? $_GET['JobID'] : '' ?>
Job Number: <input type="text" value="<?php echo jobNumber; ?>" name="jobNum"><br>
<input type="submit" name="submit" value="Submit">
</form>
Try using isset and post method to check if variable are declared and get the variable data on submit of form
<?php
if(isset($_POST['submit'])){
$jobid = $_POST['JobID'];
$part_id = $_POST['PartID'];
$machCode = $_POST['Machine'];
}
?>
<form action="" method="post">
Job Number: <input type="text" value="<?php echo $jobid; ?>" name="jobNum"><br>
Part Number: <input type="text" value="<?php echo $part_id; ?>" name="partNum"><br>
Machine Code: <input type="text" name="machCode" value="<?php echo $machCode; ?>"><br>
Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
Hope this help
This question already has answers here:
Make a link use POST instead of GET
(11 answers)
Closed 7 years ago.
Is there a way to replicate this in <a href="blah.php">?
<form action="http://localhost/php/suburb_added.php" method="post">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
in suburb_added.php... i have this to capture
if (!empty($_POST['suburb']))
To a table form....
<td align="left"><a href="suburb_added.php"><?php echo $row['id'];?></td>
how to create the items below from a table? The goal is when I click the result from <?php echo $row['id'];?>, I should be able to get the value of "id" and process it in suburb_added.php using similar to if (!empty($_POST['suburb']))
<form action="http://localhost/php/suburb_added.php" method="post">
<input type="text" name="suburb" size="30" value="" />
what do you whant i don't understand?? I can help you
<?php
if(!isset($_POST['submit'])){
?>
<form action="" method="post" name="submit">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
<?php
} else {
//paste here your code from http://localhost/php/suburb_added.php
echo "you doing post in this page.";
}
?>
<!--Try using header
like this:-->
if($_POST)
{
header('location:login-form.php');
}
else
{
echo "";
}
Change the PHP script so it uses $_REQUEST instead of $_POST. This variable combines the contents of $_POST and $_GET. Then you can have a link like
<?php echo $row['id'] ?>
i am trying to collect data from the user in a form and display the data back to him .
i am using WAMP.
here is my html code
<FORM METHOD="POST" ACTION="submit.php">
<INPUT type="text" name="URL" size=17 value="http://">
<INPUT type="text" name="user" size=17>
<INPUT type="text" name="email" size=17>
<INPUT type="submit" value="Submit" name="submit"/>
<INPUT type=reset value="Clear">
</form>
here is my submit.php code
<?php
if (isset($_POST['URL'])){
echo "set";
}
else
{
echo "not set";
}
?>
when i execute this i am always getting "not set" as the output.
thanks.
It should be $_POST not $post, so your code should be :-
<?php
if (isset($_POST['URL'])){
echo "set";
}
else
{
echo "not set";
}
?>
Also your form tag should not contain encytype="text/plain" because PHP doesn't handle it (and it is not a bug)
Valid values for enctype in <form> tag are:
application/x-www-form-urlencoded
multipart/form-data
So remove encytype="text/plain"
<?php
if (isset($_POST))
{
echo "set";
}
else
{
echo "not set";
}
?>
try this
Remove
ENCTYPE="text/plain"
from the form
So the form should look like
<form method="POST" action="submit.php">
And its $_POST not $POST
if (isset($POST['URL'])){
should be
if (isset($_POST['URL'])){
Here is an example of handling the form
<?php
if(isset($_POST["submit"])){
if (isset($_POST['URL']) && $_POST['URL'] != ''){
echo "set";
}
else
{
echo "not set";
}
}
?>
<FORM METHOD="POST" ACTION="submit.php" >
<INPUT type="text" name="URL" size=17 value="http://">
<INPUT type="text" name="user" size=17>
<INPUT type="text" name="email" size=17>
<INPUT type="submit" value="Submit" name="submit"/>
<INPUT type=reset value="Clear">
</form>
We are using very simple php custom template system using oop approach, but when we submit form, its not getting $_POST[] results. Please have a look at main code...
switch($act) { //$act= $_GET['Act'];
case 'Add':
$add_product = new Product();
print_r($_POST);
if(!empty($_POST)) {
echo $_POST['name']; //to check if its getting value
}
include('templates/edit_product.tpl');
break;
}
and here is edit_product.tpl...
<form action="<?php echo BASE_URL; ?>products.php?Act=Add" method="post">
<input type="text" size="50" name="name" />
<button type="submit" name="submit">submit</button>
thanks for your support.
<form action="<?php echo BASE_URL; ?>products.php?Act=Add" method="post">
<input type="text" size="50" name="name" />
<input type="submit" name="submit" value="submit" />
</form>
we got the problem, Thanks. We were using if(!empty($errors)) instead of if(empty($errors))