Jump to content

PHP form


aus31

Recommended Posts

Hello,

 

i am a bit new to PHP and so i need a bit of help.

 

I want to make a php form that will send all the data of that form to a certain page that is protected with a password so only the website admin can access it.  How can i do that? I already have a OS login system installed!!!

Link to comment
Share on other sites

A form is posted by HTML, and received by PHP.

You do so by using the action function to your form tag.

<form method="POST" action="your_PHP_script.php">

 

When you press the submit button on your form there will be created variables that a php script could fetch.

This you could be done by using this code:

	$your_php_variable = !empty($_POST ['name_of_form_tag']) ? $_POST['name_of_form_tag'] : '';

This code also makes sure the variable is not empty, witch could produce an error with some databases.

 

now the form input is in a php variable that you could use to whatever you want. Who that is able to see the data you control with your php. 

 

And as pikachu says, post some code and describe your errors.

 

Link to comment
Share on other sites

You can see the form code below. What i don't know is how to write a code that will send all the data from the form below to a certain page of my website, where the data can then be viewed. Am i making any sense?How can this be done?

 

<form name="contactform" method="post" action="http://domain.com/send.php"><table width="790" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="16%" align="left" valign="middle" class="bodytext"><p class="content-subeading style1 style1">Full name </td>

<td width="28%"><input  type="text" name="name"  class="one" maxlength="50" size="30"> </td>

<td width="56%" rowspan="5"> </td>

</tr>

<tr>

<td height="49" class="bodytext"><p class="content-subeading style2">Company</td>

<td><input  type="text" name="company"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td class="bodytext"><p class="content-subeading style2">Email</td>

<td><input  type="text" name="email"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td height="38" class="bodytext"> </td>

<td align="left" valign="bottom"> 

  <textarea name="comment" cols="45" rows="10" id="comment" class="two"></textarea></td>

</tr>

<tr>

  <td class="bodytext"> </td>

  <td align="left" valign="top"><input type="submit" name="Submit2" value="Send" /> </td>

  </tr>

</table></form>

Link to comment
Share on other sites

1. page 1 is the form page

2. page 2 is 'send.php', it gathers the data from the form variables (via $_POST)and stores them in a database table

3. page 3 is the admin login page

4. page 4 (A) restricts access to the admin; (B) retreives the data from the database and displays it for the admin to view

Link to comment
Share on other sites

This form send all its data to http://domain.com/send.php.

You need to change this to the page name that is supposed to handle the data.

 

On this page you need to collect all the data and save them to a database.

 

Take a look on this link to learn the basics on how to handle form data with php.

http://www.tizag.com/phpT/forms.php

Link to comment
Share on other sites

This form send all its data to http://domain.com/send.php.

You need to change this to the page name that is supposed to handle the data.

 

On this page you need to collect all the data and save them to a database.

 

Take a look on this link to learn the basics on how to handle form data with php.

http://www.tizag.com/phpT/forms.php

 

You can see the the php code that send the form data below. The code send the data to an email address...what do i need to change in the code so that the data will be sent to a certain page on my website?

 

<?php

if ($_POST["email"]<>'') {

$ToEmail = 'test@test.com';

$EmailSubject = 'Contact us ';

$mailheader = "From: ".$_POST["email"]."\r\n";

$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$MESSAGE_BODY = "Full name ".$_POST["name"]."<br>";

$MESSAGE_BODY .= "Email address: ".nl2br($_POST["email"])."<br>";

        $MESSAGE_BODY .= "Company: ".$_POST["company"]."<br>";

$MESSAGE_BODY .= "Subject: ".$_POST["subject"]."<br>";

        $MESSAGE_BODY .= "Message: ".$_POST["message"]."<br>";

       

     

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

?>

Thank you for contacting us. Your message was sent.

<?php

} else {

?> <form name="contactform" method="post" action="http://www.domain.com/send.php"><table width="790" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="16%" align="left" valign="middle" class="bodytext"><p class="content-subeading style1 style1">Full name </td>

<td width="28%"><input  type="text" name="name"  class="one" maxlength="50" size="30"> </td>

<td width="56%" rowspan="5"> </td>

</tr>

<tr>

<td height="49" class="bodytext"><p class="content-subeading style2">Company</td>

<td><input  type="text" name="company"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td class="bodytext"><p class="content-subeading style2">Email</td>

<td><input  type="text" name="email"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td height="38" class="bodytext"> </td>

<td align="left" valign="bottom"> 

  <textarea name="comment" cols="45" rows="10" id="comment" class="two"></textarea></td>

</tr>

<tr>

  <td class="bodytext"> </td>

  <td align="left" valign="top"><input type="submit" name="Submit2" value="Send" /> </td>

  </tr>

</table></form>

<?php

};

?>

Link to comment
Share on other sites

If you just send the data to a web page the data will be lost when the user moves away from that site.

What do you intend to do with this data? To keep the data you need to store it in a database.

 

I want to keep the data on the webpage!

Link to comment
Share on other sites

Then you need to store your data to a database.

You could store it directly into your web page using fwrite, but i guess thats not what you want to do.

 

You want to post the data to a web page, what type of page is this? Some kind of commenting function?

 

If you got no clew on how to do this i recommend some more reading for you.

http://www.tizag.com/phpT/

http://www.w3schools.com/php/default.asp

 

Focus on form handling and database connections.

 

You could hope that someone would write you your code, but i think you have to wait for some time.

Read a bit, write some code and then ask for help when you have some errors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.