tmwes Posted June 12, 2013 Share Posted June 12, 2013 I'm kind of a jack of all trades and master of none; and by no means a PHP expert. I know enough to get by. I have an HTML form where users select the files they want, then when they submit the files are emailed to them. This function is working fine. I also want them to have the option to download the files; when I point the form to this function, it is also working fine. What I would like to do is have the user select on the form via radio button if they want email or download, and for the PHP to select the function based on that. However, I can't seem to get this basic IF statement to work. This works, and returns the value of the radio button: function choosejob($frmfunction) { if ($frmfunction === 2) { echo $frmfunction; } else { echo $frmfunction; } } choosejob($frmfunction) function choosejob($frmfunction) { if ($frmfunction === 2) { create_zip($file_path,$files,$zipname) } else { smtpmailer($to, $from, $from_name, $subject, $body, $file_path,$files) } } choosejob($frmfunction) The second snippet does not work. It returns "Parse error: syntax error, unexpected '}' in /home/lesroco/public_html/SEND/combined.php on line 108" (108 is just above the 'else') If I call either the create_zip or the smtpmailer functions instead of choose job, either work fine. I'm sure it's something simple I'm missing, but I've been banging my head against the desk trying to figure it out. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Dathremar Posted June 12, 2013 Share Posted June 12, 2013 (edited) You are missing semicolons ( ; ) at the end of those lines. Try: function choosejob($frmfunction) { if ($frmfunction === 2) { create_zip($file_path,$files,$zipname); } else { smtpmailer($to, $from, $from_name, $subject, $body, $file_path,$files); } } choosejob($frmfunction); Edited June 12, 2013 by Dathremar Quote Link to comment Share on other sites More sharing options...
tmwes Posted June 12, 2013 Author Share Posted June 12, 2013 PERFECT! I knew it was something simple; I assumed since when you usually call a function you DON'T have semicolons you didn't need it in the IF statement. The other problem once I cleared that hurdle was I had to declare the variables inside each condition; now it is working like a charm! function choosejob($frmfunction) { if ($frmfunction == '2') { $file_path=$_SERVER['DOCUMENT_ROOT'].'/';//Download Files path $files = $_POST['image']; $zipname = time().'LesroImages.zip'; create_zip($file_path,$files,$zipname); } else { $to = $_POST["email"]; $from = 'info@lesro.com'; $from_name = 'Lesro Industries'; $subject = 'Lesro Images'; $body = 'Here are the files you requested.'; $file_path=$_SERVER['DOCUMENT_ROOT'].'/';//Download Files path $files = $_POST['image']; smtpmailer($to, $from, $from_name, $subject, $body, $file_path,$files); } } choosejob($frmfunction) Quote Link to comment Share on other sites More sharing options...
DaveyK Posted June 12, 2013 Share Posted June 12, 2013 You should turn on error reporting. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.