Jump to content

[SOLVED] New to php - form basics


JoeLongstreet

Recommended Posts

Hey all,

 

Real new to php here but I'm starting to understand the basics.  I've done a little object oriented programming before, but not much.  I wrote this small chunk of code but it isn't really working how I expected.

 

The goal here is to collect some information, email it to someone, and then send the user to one of four other pages depending on what their form said. 

 

Can you user the header function within a switch like this? 

 

Thanks for any help you can provide,

 

Joe

 

<?php
if(isset($_POST['submit'])) {

$to = "[email protected]"; 
$subject = "Mail from myWebsite.net";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$company = $_POST['company'];
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];

$body = "New Download Requested\n\n Download: $dropdown\n Name: $name_field\n E-Mail: $email_field\n Company: $company_field\n Heard about Us: $option";

mail($to, $subject, $body);
switch($dropdown) {
	case [download1]:
	header( "Location: http://www.mywebsite.net/download1.html" );
	break;

	case [download2]:
	header( "Location: http://www.mywebsite.net/downlaod2.html" );
	break;

	case [download3]:
	header( "Location: http://www.mywebsite.net/download3.html" );
	break;

	case [download4]:
	header( "Location: http://www.mywebsite.net/download4.html" );
	break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/
Share on other sites

Hey,

 

Thanks for the help.  I tried it both ways but now I'm getting this error

 

Parse error: syntax error, unexpected $end in /home/clean34/public_html/jenningspr/downloads.php on line 33

 

Line 33 is where the program closes out.

 

I've attached the html, maybe it could be of some help

 

Joe

 

<form method="POST" action="downloads.php">
  <table width="719" border="0">
  	<tr>
    <td> </td>
    <td><label>
      <select name="drop_down" size="1">
        <option value="download1" label="download1">Download 1</option>
        <option value="download2" label="download2">Download 2</option>
        <option value="download3" label="download3">Download 3</option>
        <option value="download4" label="download4">Download 4</option>
      </select>
    </label></td>
    </tr>
    <tr>
      <td width="131"><div align="right">Your Name:</div></td>
      <td width="274"><label>
        <input name="name" type="text" size="40" />
      </label></td>
    </tr>
    <tr>
      <td><div align="right">Your Email:</div></td>
      <td><label>
        <input name="email" type="text" size="40" />
      </label></td>
    </tr>
    <tr>
      <td><div align="right">Your Company:</div></td>
      <td><label>
        <input name="company" type="text" size="40"/>
      </label></td>
    </tr>
    <tr>
    <td></td>
    <td>How did you hear about us?<br /><br />
    	<input name="input1" type="radio" />Saw a Speaker<br />
    	<input name="input2" type="radio" />Googled It<br />
        <input name="input3" type="radio" />Heard From a Friend<br />
        <input name="input4" type="radio" checked="checked" />Other<br />
</td>
    </tr>
    <tr>
    	<td></td>
        <td><input name="submit" type="submit" value="Submit" />
          <input name="input" type="reset" value="Reset" /></td>
        </tr>
  </table>
</form>

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.