Jump to content

Calling function inside IF statement


tmwes

Recommended Posts

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!

Link to comment
Share on other sites

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 by Dathremar
Link to comment
Share on other sites

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)
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.