here is only part of my code, the action does not well ...action. when i view in the google javascript tools i have an id in the action line
when i hit the submit button, nothing happens, its suppose to go to php/form.php with ID 28 in this instance
......
if (mysqli_num_rows($result))
{
while ($row = mysqli_fetch_assoc($result))
{
?>
<form name="form-list" method="post" action='php/form.php?id=<?php echo $row["id"]; ?>' >
<table>
<tr>
<td valign="top">
<label for="surname">Surname</label>
</td>
<td valign="top">
<?php echo $row["title"]; ?>
</td>
</tr>
<tr>
<td valign="top">
<label for="name">Id</label>
</td>
<td valign="top">
<input type="text" value='<?php echo $row["id"]; ?>' name="name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<input type="button" value="Submit" />
</td>
</tr>
<?php } } ?>
</table>
</form> .....
<input type="submit" value="Submit" />
The input type is not button it is submit.
The value attribute just changes the written text on the button but does not change it's behavior.
Note to the other answers:
Using POST is fine if he handles the request in the right way. In the given code example everything except the submit button works and is fine.
In this case the id is transmitted as a GET and all other values are submitted via POST. You can mix them.
Later you do have to use $_GET["id"] and $_POST["name"].. or you can even use $_REQUEST["..."] for all of them.
Related
i update php form and change the value but it cant change it saves the same previous value
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id="total_fees">
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
</tr>
Please see the screenshot of source code and input filed . i changed the value in input field but it remain same in source code and save source code value db
The input values not immediately affect on your input but You will get your new value while you submitting your form.
So submit your form and then print the values of the Request. You will find the new value of total_fees into the request parameters.
HTML CODE
<form name="jqueryForm" method="post" id="jqueryForm" enctype="multipart/form-data" onSubmit="return validme();">
<table border="0" cellspacing="15" cellpadding="0" width="100%" >
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id=total_fees>
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
<td width="40%"></td>
</tr>
<tr>
<td width="22%">Discount in <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo percent; ?>" checked="checked" onChange="show_record()" />% or <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo cash; ?>" onChange="show_record()" />Cash</td>
<td width="38%"><input type="text" class="input_text" name="concession" id="concession" value="<?php if($_POST['concession']) echo $_POST['concession']; else if($row_record['discount'] !=0) echo $row_record['discount']; else echo 0; ?>" onBlur="show_record()"/>
</td>
<td width="40%"></td>
</tr>
</table>
<input type="submit" value="Save Record" name="save_changes" />
</form>
PHP CODE FOR SAVE IN DB
if(isset($_POST['save_changes']))
{
$total_fees=($_POST['total_fees']) ? $_POST['total_fees'] : "0";
$data_record['total_fees']=$total_fees;
$courses_id=$db->query_insert("enroll", $data_record);
}
I would like click on submit and the value input in the field to be stored in database.
However, I do not want to use a form action. Is it possible to do it without creating form action with PHP?
<tr>
<form method="post">
<tr>
<td>
<label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
<input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" id="submit" />
</td>
</tr>
<?php
if(isset($_POST['submit']))
{
var_dump($_POST); exit;
$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
However, I do not want to use a form action. Is it possible to do it
without creating form action with PHP?
No, that's not possible.
Just do it like this:
<tr>
<form method="post" action="mypage.php">
<tr>
<td>
<label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
<input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" id="submit" />
</td>
</tr>
</form>
<?php
if(isset($_POST['finish_product']))
{
var_dump($_POST); exit;
$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
I've been looking through the site and going over pointers on similar problems but none have seemed to work for me. I'm a wee bit stuck, hoping someone can point out my stupidity.
I created a basic form to test as my main site was giving me problems. There is no error checking or filtering for malicious code, it's just a test to figure out why it won't work.
I can't retrieve any data from a textarea.
All other types work, text, number, etc... all fine.
Here is my basic form, can anyone see the error of my ways?
<?php
require_once('header.php');
if(isset($_POST['submit']))
{
echo "<br>single line comment: " .$_POST['singlelinecomment'];
if (!isset($_POST['comments']))
{
echo "<br>nothing in textarea data, move along, move along";
}
else
{
$comments = $_POST['comments'];
echo "<br>comments: ". $comments;
}
}
?>
<form name="conversation-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
form="conversation-form" remove it from textarea, it's the main cause.
Plus, you don't need this name="conversation-form" in <form>, unless you want to use it for CSS purposes, then use id="conversation-form" or class="conversation-form"
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
^^^^^^^^^^^^^^^^^^^^^^^^ remove it
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
Hi try to submit user data from client side to server side by changing action attribute after validation has completed (It is something I did in the past and suddenly it is not working).
My html form(post)
<!-- Submit data to server-side -->
<form id="register" method="post">
<table class="tableReg" border="0">
<tr class="rowReg">
<td>User name:</td>
<td><input onfocus="resetColor('userID')" type="text" id="userID" name="user"></td>
<td id=note1></td>
</tr>
<tr class="rowReg">
<td>Password:</td>
<td>
<input onfocus="resetColor('passwordID1')" type="password" id="passwordID1" name="password1">
</td>
<td id=note2></td>
</tr>
<tr class="rowReg">
<td>Repeat Password:</td>
<td>
<input onfocus="resetColor('passwordID2')" type="password" id="passwordID2" name="password2">
</td>
<td id=note3></td>
</tr>
<tr class="rowReg">
<td>Email:</td>
<td><input onfocus="resetColor('emailID1')" type="email" id="emailID1" name="email1"></td>
<td id=note4></td>
</tr>
<tr class="rowReg">
<td>Repeat Email:</td>
<td><input onfocus="resetColor('emailID2')" type="email" id="emailID2" name="email2"></td>
<td id=note5></td>
</tr>
</table>
<input type="button" onclick="checkInput()" value="Submit">
</form>
If you see after I press the sumbit button the information is checked and if passed validation is being sent to server side, I used javaScript:
function checkInput(){
var regexUser = /^(?=.{1,20}$)[a-zA-Z0-9]+$/;//all letters ad number and size between 1-20
var regextPwd = /^(?=.{8,8}$)(?=.*[a-zA-Z])(?=.*\d)(?=.*[!#$%&? "]).*$/; //Password must contain 8 characters and
// at least one number, one letter and one
// unique character such as !#$%&?
//Email regex
var regexMail = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var errorArr = new Array(0,0,0,0,0);
document.getElementById("register").action = "databasebuilder.php";}
Now after I validate input it suppose to send to databasebuilder.php which is in the same directory on my local host but it doesn't!
I already tested it without and it should be reachable why document.getElementById("register").action is not working.
Why dont you submit the form by yourself. Like this...
document.getElementById("register").action = "databasebuilder.php";
document.getElementById("register").submit();
Try this,
Add this in your js function
document.getElementById("register").action= "databasebuilder.php";
reutrn true;
Also change the type from button to submit like
<input type="submit" onclick="return checkInput()" value="Submit">
I have this code which permits me to display all the data in the database as a textarea, I need to update them by clicking a update button!
Based on this one, is supposed to make me edit them, but when i click submit it doesn't...
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center">
<? $id[]=$rows['id']; ?>
<? echo $rows['id']; ?>
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
</td>
<td align="center">
<input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>">
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="submit" name="Submit" value="Submit"/>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit)
{
for($i=0;$i<$count;$i++)
{
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1)
{
header("location:update_multiple.php");
}
Yes because you forget your id's
<? $id[]=$rows['id']; ?> cannot be passed like that
<input type="hidden" name="id[]" value ="<?php echo $rows['id']; ?>" /><? echo $rows['id']; ?>
and script if($Submit){ should be if($_POST['Submit'] != ''){
You aren't defining $Submit in your post, so the stuff in the { ... } is never executed.
You should try something like this for your update:
if(isset($_POST[$name]))
{
// update stuff
}
In your code, as the if statement never executes, $result is never set, so the user isn't redirected away - it will just show the same page each time.
To check if a post occur when clicking a button should be set as follow:
In the <form>tag add the following
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
And lastly, where you check if the button was clicked:
if(isset($_POST['Submit'])) {
//Update fields
}
Remember that the submit button name field is case sensitive in php