Jump to content

POST Help


phpcode

Recommended Posts

I'm trying to create a contact form but I'm stuck on this:

 

<?php

$file = fopen("contact.txt", "a+");

foreach($_POST as $key => $value); 

fwrite($file, $value. "\n\n===========================\n\n");

fclose($file);


?>

 

What I want it to do is get all the forms field names and what the user entered into them and write it to the contact file but it only shows me the last field name. I've tried putting the foreach() in fwrite() but that just gives me an error.

Link to comment
https://forums.phpfreaks.com/topic/90488-post-help/
Share on other sites

when you set the name that will be your post variable

 

here is an example:

 

<form id="form1" name="form1" method="post" action="">

  <input name="name" type="text" id="name" />

  <input type="submit" name="Submit" value="Submit" />

</form>

<?php
$name = $_POST['name'];
echo $name;
?>

Instead of writing it to a file, you should do a database!

Link to comment
https://forums.phpfreaks.com/topic/90488-post-help/#findComment-463931
Share on other sites

You're not even running a loop there :P

 

<?php

$file = fopen("contact.txt", "a+");

foreach($_POST as $key => $value) {

fwrite($file, $value. "\n\n===========================\n\n");
}

fclose($file);


?>

 

This is an odd way of doing contact forms.

Keep in mind that the button is also a $_POST. so that's gonna show up on your file.

Link to comment
https://forums.phpfreaks.com/topic/90488-post-help/#findComment-463940
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.