PHP conditional ignoring value in SELECT

Having an odd issue with a portion of a PHP script that emails a user if their item is approved for publication.

The administrator reviews the item through a form, and one of the fields is a simple SELECT with values Y and N. N is the default. The idea being if it’s set to N, the item isn’t published (although it can be edited and the db is updated accordingly). If it’s set to Y, it should send an email to the user’s email address (which is taken from one of the fields) to let them know the item has been approved.

The strange thing is that the if statement seems to be ignoring the status of the SELECT and sending out approval emails even if Published = N.

The SELECT in the fom is:


<select name=\\"_Published\\" size=\\"1\\"><option>Y</option><option selected>N</option></select>

And the part of the code that sends out the email is:


if ($title8 = 'Y'){
	$mailto = $email;
	$mimebound = md5(uniqid(time()));
	$subject = "Your Item has been approved";
	$headers ="From: Customer Area<sales@somedomain.com>\
";
	$headers .="MIME-Version: 1.0\
";
	$headers .="Content-Type: multipart/mixed; boundary=\\"".$mimebound."\\"\
\
";
	$message = "Your Item " . $title2 . " has been approved and added to the Items For Sale.";
}

So it should only send out the mail if $title8 (which is a POST of the SELECT value) = Y. But it’s doing it regardless of the value…???

May have fixed it actually, by also adding an if for == ‘N’.

Thanks!

Unfortunately I now get an “ERROR: Query was empty” error if the value is N. If I set the value to Y then the process works fine. Any ideas?

here’s what i found out on the code you have

you forgot ==


if ($title8=='Y'){

put the value on html as well


<option value="Y">Y</option>
<option selected value="N">N</option>