简体   繁体   中英

php wont post my html form

Html:

<form method="post" action="create.php">
Job #: <input type="text" name="jobnum">
<br>
Program: <input type="text" name="program"><br />
Ship Date: <input type="text" name="shipdate"><br />
Description: <input type="text" style="height:100px; width:85%" name="description"><br /><br />
Proto Verified By: <input type="text" name="name"><br /><br />
Additional Notes: <input type="text" style="height:100px; width:85%" name="notes"><br />
<input type="submit" name="value" value="submit" />
</form>

php:

$savedata = $_REQUEST['savedata'];
if ($savedata == 1){

$data = $_POST['jobnum']  . "\r\n";
$data .= $_POST['program']  . "\r\n";
$data .= $_POST['description']  . "\r\n";
$data .= $_POST['name'] . "\r\n";
$data .= $_POST['notes']  . "\r\n";

$file = "YOURDATAFILE.txt"; 

$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
echo "Your Form has been Submitted!";

}

I am not sure why my php will not post my form. My submit goes the the php page but it is completely blank. I am kind of new to code so I may need some detailed response...

您需要添加一个隐藏表单字段,将savedata设置为1,以便if语句完成:

<input name="savedata" value="1" type="hidden" />

Try this, You have not passed or posted with name of savedata , from form submit button, i have used as below

if(isset($_POST['value'])){

instead of

$savedata = $_REQUEST['savedata'];
if ($savedata == 1){

There's no savedata named field in the form. So i suggest that you use submit button's name to check if form is submitted. And isset() for checking value in php.

$savedata = $_REQUEST['value'];
if (isset($savedata)){
   ...

There is no savedata element defined in the form.

I would also suggest you to be consistent in your code, get all elements with $_POST or $_REQUEST. Also, assign value to the name attribute of the form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM