Jump to content

if's not working properly


blink359

Recommended Posts

Hi there, I have created an email script and i want it to email a different email depending on the subject chosen by raido boxes however the if's aren't doing what they should, If i select say recruitement it choses the last option and has the wrong subject here is my code:

<html>
<head>
</head>
<body>
<form action="contact.php" method="post">
<fieldset>
<legend>Contact Us</legend>
Your Email:*<br>
<input type="text" name="email"><br>
Subject:*<br>
Recruitment Enquiry:<input type="radio" name="subject" value="Recruitment">
Absense Notification:<input type="radio" name="subject" value="Absense">
General Enquiry<input type="radio" name="subject" value="Enquiry">
<br>
Message:*<br>
<textarea name="message" cols="50" rows="5"></textarea><br>

<input type="submit" value="Send Email">
</form>
Required fields are marked with a *<br><br>
<?php
if(isset($_POST))
{
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

//checcking that all relevent information is entered and correct

if(!$email || !$message)
{
	$errmessage ="Please fill in all required fields.";	
}
if($subject="Recruitment")
{
	$to="email1";	
}	
if($subject="Notification")
{
	$to="email2k";
}	
if($subject="Enquiry")
{
	$to="email3";	
}
//Sending the email if nothing is wrong

if(!$errmessage)
{
header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message."");
}else{
	echo $errmessage;
}
}
?>
</body>
</html>

If anyone can help it would be greatly appriciated

 

Thanks,

 

blink359

Link to comment
Share on other sites

 

if($subject="Notification"), yet you've used value="Absense".

 

I would change the radio button values to 1, 2, 3.

 

So..

Recruitment Enquiry:<input type="radio" name="subject" value="1">
Absense Notification:<input type="radio" name="subject" value="2">
General Enquiry<input type="radio" name="subject" value="3">

...don't forget to change the processing script!

Link to comment
Share on other sites

It's not the html its the php i moved half the script to another one and the drop down passed on the correct value the if statements are changing the value

 

Script 1:

<html>
<head>
</head>
<body>
<form action="contact.php" method="post">
<fieldset>
<legend>Contact Us</legend>
Your Email:*<br>
<input type="text" name="email"><br>
Subject:*<br>
<select name="subject">
<option value="1">Recruitment</option>
<option value="2">Absense</option>
<option value="3">Enquiry</option>
</select>
<br>
Message:*<br>
<textarea name="message" cols="50" rows="5"></textarea><br>
Please type the code shown in the image:<br><script type="text/javascript" src="http://webspamprotect.com/captcha/3096/"></script>
<noscript>This form protected by <a href="http://webspamprotect.com" target="_blank" title="Web form spam protection">WebSpamProtect</a>. JavaScript must be enabled in your browser to view this image.
</noscript> <input type="text" name="wsp_code"/><br>
<input type="submit" value="Send Email">


</form>
Required fields are marked with a *<br><br>
<?php
if(isset($_POST))
{
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "nathan_k_boothby_1994@hotmail.co.uk";

//checcking that all relevent information is entered and correct



include_once("wsp_captcha.php");

if (WSP_CheckImageCode() != "OK") 
{
   		 $errmessage="The image code you have entered is incorrect.";
}

//Sending the email if nothing is wrong

if(!$errmessage)
{
header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message."");
}else{
	echo $errmessage;
}
}
?>
</body>
</html>

 

Script 2:

<?php
$to = $HTTP_GET_VARS["to"];
$subject = $HTTP_GET_VARS["subject"];
$message = $HTTP_GET_VARS["message"];
$email = $HTTP_GET_VARS["email"];
if(!$email || !$message)
{
	$errmessage ="Please fill in all required fields.";	
}
if($subject="1")
{
	$to="nathan.boothby@kingscollegeguildford.com";	
}	
if($subject="2")
{
	$to="nathan.boothby@kingscollegeguildford.com";
}	
if($subject="3")
{
	$to="nathan.boothby@kingscollegeguildford.com";	
}	
if($subject="1")
{
	$subject="Recruitment";	
}	
if($subject="2")
{
	$subject="Absense";
}	
if($subject="3")
{
	$subject="Enquiry";	
}
	mail($to, $subject, $message ,"From: $email"); 
echo("Email Sent");
?>

Link to comment
Share on other sites

One equal sign = is an assignment operator and except when you are assigning a zero/null/false value on the right-hand side of the statement, assignment statements are always true.

 

All your if($var = 'string') are assigning the string to the $var and testing the result of that assignment.

 

Two equal signs == is a comparison operator.

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.