JoeLongstreet Posted September 25, 2008 Share Posted September 25, 2008 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 More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 What is it doing that's not expected? Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650665 Share on other sites More sharing options...
JoeLongstreet Posted September 25, 2008 Author Share Posted September 25, 2008 It gives me this error: Parse error: syntax error, unexpected '[' in /home/clean34/public_html/jenningspr/downloads.php on line 17 which is the line the switch statement starts Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650683 Share on other sites More sharing options...
Zhadus Posted September 25, 2008 Share Posted September 25, 2008 Where your switch statement is, the case statements should either be "download1" or "[download1]" The brackets are causing an error, put the variable in quotes. Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650696 Share on other sites More sharing options...
JoeLongstreet Posted September 25, 2008 Author Share Posted September 25, 2008 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> Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650724 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2008 Share Posted September 25, 2008 The "unexpected end" means you haven't closed a block with a "}" somewhere or closed a quote. Ken Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650729 Share on other sites More sharing options...
hagakure Posted September 25, 2008 Share Posted September 25, 2008 As ken said, the unexpected end error is from having an open "{" in the code. In this case (no pun intended), the open "{" is opening isset if at the beginning. You open the if to check if submit is set in the $_POST array but never close it. Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650733 Share on other sites More sharing options...
JoeLongstreet Posted September 25, 2008 Author Share Posted September 25, 2008 Oh jeez, Don't I feel silly now. Thanks for pointing that out. I feel as if I should have noticed that. Thanks, Joe Link to comment https://forums.phpfreaks.com/topic/125828-solved-new-to-php-form-basics/#findComment-650804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.