I have a form on a PHP page which adds a contact into a MySQL table.
But my validation refuses to work. I have edited it a few times but when I click Add New Contact button, it adds them even if some fields are empty.
I am still getting the grasp of PHP, but I am sure my mistake is missing something simple.
<?php
// Don't post the form until the submit button is pressed.
$requiredFields = array (
"name",
"email",
"extension",
"extension"
); // Add the 'name' for all required fields to this array
$errors = false;
if (isset ( $_POST ['Submit'] )) {
// Clean all inputs
array_walk ( $_POST, 'check_input' );
// Loop over requiredFields and output error if any are empty
foreach ( $requiredFields as $r ) {
if (strlen ( $_POST [$r] ) == 0) {
$errors = true;
break;
}
}
// Error/success check
if ($errors == true) {
echo 'Fields marked with a * are required';
} else {
// no errors
// ...
}
}
// check_input function
function check_input(&$data) {
$data = trim ( $data );
$data = stripslashes ( $data );
$data = htmlspecialchars ( $data, ENT_QUOTES );
return $data;
}
?>
<h2>Add Contact</h2>
<form name="form1" action="<?=$_SERVER['PHP_SELF'];?>?mode=added"
method="post">
<table class="tableStyleClassTwo">
<tr>
<td>Name:</td>
<td><div align="left">
<input type="text" name="name" />
</div></td>
</tr>
<tr>
<td>Phone:</td>
<td><div align="left">
<input type="text" name="phone" />
</div></td>
</tr>
<tr>
<td>Email:</td>
<td><div align="left">
<input type="text" name="email" />
</div></td>
</tr>
<tr>
<td>Extension:</td>
<td><div align="left">
<input type="text" name="extension" />
</div></td>
</tr>
<tr>
<td>Department:</td>
<td><select name="department">
<option value="ADMIN">ADMIN</option>
<option value="AFTER-SALES DIRECTOR">AFTER-SALES DIRECTOR</option>
<option value="ALPINE DEALER PRINCIPAL">ALPINE DEALER PRINCIPAL</option>
<option value="AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)">AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)</option>
<option value="BANDIT-VW">BANDIT-VW</option>
<option value="BOOKINGS VW">BOOKINGS VW</option>
<option value="DRIVEWAY/WASHBAYS">DRIVEWAY/WASHBAYS</option>
<option value="FINANCE AND INSURANCE">FINANCE AND INSURANCE</option>
<option value="IT DEPARTMENT">IT DEPARTMENT</option>
<option value="MARKETING DEPARTMENT">MARKETING DEPARTMENT</option>
<option value="MASTER CARS">MASTER CARS</option>
<option value="MAYOR OF PINETOWN">MAYOR OF PINETOWN</option>
<option value="NEW CAR PREP DEPARTMENT">NEW CAR PREP DEPARMENT</option>
<option value="NUMBER PLATES">NUMBER PLATES</option>
<option value="PANELBEATER - EASIFIX - CAR CARE">PANELBEATER - EASIFIX - CAR CARE</option>
<option value="PARTS">PARTS</option>
<option value="PARTS DISPATCH">PARTS DISPATCH</option>
<option value="PARTS TELESALES">PARTS TELLESALES</option>
<option value="USED CAR PREP AND ORDERS">USED CAR PREP AND ORDERS</option>
<option value="VW NEW CARS ADMIN AND STOCK CONTROL">VW NEW CARS ADMIN AND STOCK CONTROL</option>
<option value="VW NEW VEHICLE SHOWROOM">VW NEW VEHICLE SHOWROOM</option>
<option value="VW SERVICE ADVISORS">VW SERVICE ADVISORS</option>
<option value="VW WORKSHOP">VW WORKSHOP</option>
<option value="VW WORKSHOP FOREMEN">VW WORKSHOP FOREMEN</option>
<option value="WARRANTY & CLAIMS">WARRANTY & CLAIMS</option>
<option value="WORKSHOP DRIVERS">WORKSHOP DRIVERS</option>
</select></td>
</tr>
<tr>
<td colspan="2" align="centre">Back
| <input name="Submit" type="submit" id="Submit" value="Add New Contact" <?php if($disable ==1){?> disabled <?php } ?> />
</td>
</tr>
<input type="hidden" name="mode" value="added">
</table>
</form>
<?php
break;
//added a record
case 'added':
//first setup the vars
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$extension = $_POST['extension'];
$department = $_POST['department'];
//then lets use'em
$sql = "INSERT INTO address (name, phone, email, extension, department) VALUES ('" . $name . "','" . $phone . "','" . $email . "','" . $extension . "','" . $department . "')";
//echo $sql;
//return;
mysql_query($sql);
//done take me back to the main page
header('location: ' . $_SERVER['PHP_SELF']);
break;
At present I have set 4 variables, the values of which are then stored into mysql. This works fine. However, I don't want to set the values but write a line of code that takes these values from my form (on the same page). I have set the form method to POST and added specialchars to help security. Can someone pretty please show me one or two lines of code so I don't have to write ="John Doe". Please remember that I am very new all of this
<?php
// Connect to the Database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "topsecretDontTell";
$dbname = "gaming";
$connection = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
// Show error if connection fails
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() .")"
);
}
?>
<?php
// ordertbl
$customer_name = "John Doe";
$game_id = 3;
$reservation_start = "2015-01-05";
$requested_days = 1;
// removes single quotes (escapes strings)
$customer_name = mysqli_real_escape_string($connection, $customer_name);
//add into ordertbl
$query = "INSERT INTO ordertbl (customer_name,game_id,reservation_start,requested_days) VALUES ('{$customer_name}',{$game_id},'{$reservation_start}', {$requested_days})";
//Run query and test if there was a query error
$result = mysqli_query($connection, $query);
if (!$result) {
die("Database query failed.");
}
?>
<?php
//determine the name of the game via its id using a function
function GameTitle ($game_id){
$message = "";
if ($gameid ==1){
$message = "Fantasy World";
}
else if ($gameid ==2){
$message = "Sir Wags A Lot";
}
else if ($gameid ==3){
$message = "Take a Path";
}
else if ($gameid ==4){
$message = "River Clean Up";
}
else if ($gameid ==5){
$message = "PinBall";
}
else if ($gameid ==6){
$message = "Ghost girl";
}
else if ($gameid ==7){
$message = "Dress up";
}
else if ($gameid ==8){
$message = "Where is my hat?";
}
else {
$message = "Invalid ID";
}
return $message;
}
?>
</body>
</html>
<!--Link to the style sheet-->
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<!--Create Header (logo, title and navigation bar)-->
<body>
<div id='main'>
<div id='titleImage'><img title='Home' src='images/GLLogo.png' width='700' height='190' alt='Games Library Title' /></div>
<div id='menu-wrapper'>
<div id='menu'>
<ul>
<li><a href='index.html'>Home</a></li>
<li class='current_page_item'><a href='#'>Reservations</a></li>
</ul>
</div>
</div>
<!--Make the form-->
<div class="form">
<h1>Reservations</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="755" border="3" cellpadding="6">
<tr>
<td width="195" align="right" bgcolor="#FF0000"><label for="customer_name">Name:</label></td>
<td width="370"><input name="customer_name" autofocus type="text" id="customer_name" size="35" maxlength="90" required autocomplete="off" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="game_id">Game's ID:</label></td>
<td><input name="game_id" type="number" id="game_id" size="35" maxlength="50" min="1" /></td>
</tr>
<tr>
<td width="195" align="right" bgcolor="#FF0000"><button onClick="GameTitle(); return false">Search</button></td>
<td><input name="Result" type="text" id="demo" size="35" maxlength="50" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="Loan">Number of Days you wish to borrow the Game</label></td>
<td><select name="requested_days" id="requested_days">
<option selected="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></td>
</tr>
<tr> <!--put date into value field to get a calendar-->
<td align="right" bgcolor="#FF0000"><label for="reservation">Reservation Date:</label></td>
<td><input id="reservation_start" input name="reservation_start" type="" value="" placeholder="YYYY/MM/DD" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))" title="The date should be in the exact format: YYYY-MM-DD with leading zeros where necessary"/>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><label for="mysearch2">Enter your search string here : </label></td>
<td><input {background-colour: #E5F5EF;} id="mysearch2" type="search" placeholder="search"size="35" maxlength="50"/>
</tr>
<tr>
<td align="right" bgcolor="#FF0000"><input type="reset" name="Reset" id="button" value="Reset Form" /></td>
<td><input type="submit" name="button2" id="button2" value="Submit Form" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
// get rid of data in cache and close
mysqli_close($connection);
?>
Use the following, taking the POST variable from your form's <input name="customer_name"... element:
$customer_name=stripslashes($_POST['customer_name']);
$customer_name=mysqli_real_escape_string($connection,$_POST['customer_name']);
which will allow for names containing apostrophes like John O'Reilly.
Plus, you have function GameTitle ($game_id) therefore you most likely meant to use function GameTitle ($gameid)
You should use $_POST. In that array are post data. For example:
$customer_name = $_POST['name'];
I need some help with this project. I've gone as far as I can go, with no results, The inquiry form works, but I need to populate it with my sql table. I could only screen shot my sql and I have no idea of how to put it on here. The following is the scenerio: Uploading Information Directly into the Inquiry Table
In this scenario I will be using the inquiry form that I created in one of my projects, and the table named inquiry created with SQL in another project. User responses’ must be uploaded into the inquiry table by using the MySQL statements. Add the code to upload the information to the inquiry table on the email.php file (the file used to send the emails from the inquiry form). To test that the results were uploaded into the table, use an if…else statement to display to the screen if the results were uploaded or not. Add at least 3 inquiry responses.
NOTE: Be sure the fields names of the inquiry form match the values variable names created to ensure the results are uploaded into the table. If problems with uploading the results, first look at the names of the fields, and order listed.
This is my inquiry.php:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$name = $_POST ['name'];
$address = $_POST ['address'];
$city = $_POST ['city'];
$state = $_POST ['state'];
$zip = $_POST ['zip'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$major = $_POST ['major'];
$year = $_POST ['year'];
$semester = $_POST ['semester'];
$to="bgoog#mail.nira.edu, ther691#gmail.com"; //an email is sent to your email account and to
$message="To Whom It May Concern, <br>";
$message.="My information is listed below: <br><br>";
$message.="Name: $name<br>";
$message.="Address: $address<br>";
$message.="City: $city<br>";
$message.="State: $state<br>";
$message.="Zip: $zip<br>";
$message.="Phone: $phone<br>";
$message.="Email: $email<br>";
$message.="Major: $major<br><br>";
$message.="I plan to enter in the $semester of $year. <br>";
$message.="Please assist me in this matter.<br><br>";
$message.="Respectfully,<br>";
$message.="B Good<br>";
$subject="University - Inquiry Form";//The subject of the email is �University - Inquiry Form�
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <therock691#gmail.com>" . "\r\n";//the email should like it was sent from the person contacting University
$response=mail($to,$subject,$message,$headers);
if($response)
{
Echo "Email sent successfully";
}
else //
{
Echo "Error Occured while sending email";
}
$hostname = "localhost";
$username = "vde_bgood";
$password = "s0123456";
$database = "vde_bgood";
$table = "inquiry";
mysql_connect($hostname, $username, $password) or die("Unable to connect to database");
mysql_select_db($database) or die ("Unable to select db");
$fields = "id, name, address, city, state, zip, phone, email, major, semester year";
$values = "'$id', '$name', '$address', '$city', 'state', 'zip', 'phone', 'email', 'major'. 'semester', 'year'";
$query = "INSERT INTO $table ($fields) VALUES ($values)";
$result = mysql_query($query);
if($result)
echo "Thank you for completing the Inquiry Form";
else
echo "Sorry, this is not currently working";
?>
<br>
<br>
<a href='inquiry.html'>Go back to contact form</a></body>
</html>
.HTML Document:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function MM_validateForm()
{ //v4.0
if (document.getElementById)
{
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3)
{
test=args[i+2];
val=document.getElementById(args[i]);
if (val)
{
nm=val.name;
if ((val=val.value)!="")
{
if (test.indexOf('isEmail')!=-1)
{
p=val.indexOf('#');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
}
else if (test!='R')
{
num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1)
{
p=test.indexOf(':');
min=test.substring(8,p);
max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
}
}
}
else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
}
}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
}
</script>
</head>
<body>
<form action="inquiry.php" method="post" name="form1" id="form1">
<h2>Nira University Enrollment Form</h2>
<table width="500" border="1">
<tr>
<td width="171"><label for="name">Name:</label></td>
<td width="313"><input name="name" type="text" id="name" form="form1" title="name"></td>
</tr>
<tr>
<td width="171"><label for="name">Street Address:</label></td>
<td width="313"><input type="text" name="address" id="address"></td>
</tr>
<tr>
<td width="171"><label for="name">City:</label></td>
<td width="313"><input type="text" name="city" id="city"></td>
</tr>
<tr>
<td width="171"><label for="name">State:</label></td>
<td width="313"><input type="text" name="state" id="state"></td>
</tr>
<tr>
<td width="171"><label for="name">Zip Code:</label></td>
<td width="313"><input type="text" name="zip" id="zip"></td>
</tr>
<tr>
<td width="171"><label for="name">Telephone:</label></td>
<td width="313"><input name="phone" type="text" id="phone" onBlur="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zipcode','','RisNum','phone','','R','email','','RisEmail','major','','R');return document.MM_returnValue"></td>
</tr>
<tr>
<td width="171"><label for="name">Email Address:</label></td>
<td width="313"><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td width="171"><label for="name">Intended Major:</label></td>
<td width="313"><input type="text" name="major" id="major"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="select">Year:</label></td>
<td><select name="year" id="year" >
<option value="">Select Year</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select></td>
<label for="select3"></label>
<tr>
<td><label for="select">Semester:</label></td>
<td width="313"><select name="semester" id="semester" title="semester">
<option value="">Select Semester</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
<option value="Fall">Fall</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="171"><input name="submit" type="submit" id="submit" onClick="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zip','','RisNum','phone','','R','email','','NisEmail','major','','R');return document.MM_returnValue" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
I don't even know what your supposed to be asking us? However if the problem is coming from your mysql query try this:
$result = mysql_query("INSERT INTO inquiry($fields) VALUES('$values')");
You may want to check your $fields and $values variables as you have some inconsistencies. You do not have semester and year separated with a comma in $fields, but you have them separated in the $values. Also, you have a period, not a comma, in between major and semester in $values.
Now, if I'm understanding this right, you have your table with your information in it and now want to populate your form with this information. You're going to have to query your DB and select the information then display it on your form either using variables or an array.
$query = "SELECT * FROM table_name";
$result = mysqli_query($con, $query);
$data = mysqli_fetch_array($result);
Then you can use as so:
$name = $data['name'];
$address = $data['address'];
etc.
Then using PHP you can plug these variables where you would like to display them. You can find more info here: http://us1.php.net/manual/en/book.mysqli.php and here: http://www.tutorialspoint.com/php/mysql_select_php.htm.
Hope this helps.
So, I got bored and decided to try out making a simple PHP form to send an email with form data. But now, it keeps returning the same error and it's really aggravating. Here's the form info:
<table class="table-1" cellspacing="5">
<tr>
<td><label for=fullname>Full Name</label></td> <td><input type="text" name="fullname" id="fullname" placeholder="First and Last Name" /></td>
</tr>
<tr>
<td><label for=email>Email</label></td> <td><input type="email" name="email" id="email" placeholder="name#something.com" /></td>
</tr>
<tr>
<td><label>Age</label></td>
<td>
<select name="age">
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="160">160</option>
</select>
</td>
</tr>
<tr>
<td><label>Are you a programmer/developer?</label></td>
<td>
<select name="program-q">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</td>
</tr>
<tr>
<td><label for=picUrl>Picture?</label></td>
<td><input type="text" name="picUrl" placeholder="URL of your Image" /></td>
</tr>
<tr>
<td><label>Are you an Otaku?</label></td>
<td><input type="checkbox" name="otaku-yes" /> Yes </td>
</tr>
<tr>
<td><label>Do you like JROCK/JPOP?</label></td>
<td><input type="checkbox" name="jrock-yes" /> <label for=jrock-yes>Heck yeah!</label></td>
</tr>
<tr>
<td><label>Would you dress up like a maid randomly<br /> and call me 'master' all day?</label></td>
<td><input type="checkbox" name="maid-q" /> <label for=maid-q>Why Not? ;D </label></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Apply Now!" /></td>
</tr>
That part works fine, and then this is the PHP:
<?php
$to = "jake#weeshare.ws";
$subject = "New Submission";
$email = $_POST['email'];
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$programmer = $_POST['program-q'];
$picUrl = $_POST['picUrl'];
$otaku = $_POST['otaku-yes'];
$jrock = $_POST['jrock-yes'];
$maid = $_POST['maid-q'];
$headers = "From: $email";
$sent = mail("$to, \n $subject, \n $fullname, \n $age, \n $programmer, \n $picUrl, \n $otaku, \n $jrock, \n $maid);
if ( $sent ) {
echo "Good.";
} else {
echo "Not good.";
}
?>
Everytime I click 'Submit,' this is what it returns. No matter how many times I've tweaked it, my server just keeps sending this:
Parse error: syntax error, unexpected T_STRING in /home/weeshare/public_html/wtf/contact.php on line 15
Any ideas on what's wrong? I've been at this for hours now and still nothing is working..
You're missing a " at the end of the mail() call argument.
I suggest using an editor which does syntax highlighting, it makes this sort of error easy to spot.
Also see PHP Parse/Syntax Errors; and How to solve them?
And as Michael Berkowski points out, your mail() call is wrong, get rid of the quotes and the \n.
The syntax highlighting here on SO should give you an idea of what's gone wrong! Perhaps you meant something more along the lines of this (N.B. removed $headers and modified mail() call):
$to = "jake#weeshare.ws";
$subject = "New Submission";
$email = $_POST['email'];
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$programmer = $_POST['program-q'];
$picUrl = $_POST['picUrl'];
$otaku = $_POST['otaku-yes'];
$jrock = $_POST['jrock-yes'];
$maid = $_POST['maid-q'];
$sent = mail($to, $subject, $fullname . ' ' . $age . ' ' . $programmer . ' ' . $picUrl . ' ' . $otaku . ' ' . $jrock . ' ' . $maid);
if($sent) {
echo "Good.";
}
else {
echo "Not good.";
}
Below is my php contact form:
Page the user inputs information:
<div style="padding-left: 50px">
<p class="arial"><strong></strong><br /><br /></p>
<form action="freecontact2formprocess.php" method="post">
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <font color=#E42217 >Please ensure all card details are correct.</font>
<br /><br /></td>
</tr>
<tr>
<td valign="top"><table width="400px" class="freecontact2form">
<tr>
<td colspan="2"><br />
<br />
<div class="freecontact2formmessage"> </div></td>
</tr>
<tr>
<td valign="top"><label for="subject_type" >Subject Type:<span class="required_star"> * </span></label></td>
<td valign="top"><select name="subject_type" id="subject_type">
<option selected="selected" value ="Maths">Maths</option>
<option value ="English">English</option>
<option value ="Biology">Biology</option>
<option value ="Chemistry">Chemistry</option>
<option value ="Physics">Physics</option>
<option value ="History">History</option>
</select></td>
</tr>
<tr>
<td style="text-align:center" colspan="2"><br /><br /> <input src="../../images/submit1.png" name="submit" type="image"> <br /><br /> <!-- If you want to remove this author link, please purchase an unbranded version from: http://www.freecontact2form.com/unbranded_form.php Or upgrade to the professional version at: http://www.freecontact2form.com/professional.php --> <br /><br /></td>
</tr>
</table></td>
<td valign="top"> </td>
</tr>
</tbody>
</table>
</form> <br />
<p> </p>
<p> </p>
This is freecontact2formprocess.php:
if(isset($_POST['subject_type'])) {
include 'freecontact2formsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['subject_type']) ||
!isset($_POST['testvariablealwaysset']) ||
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$subjecttype_from = $_POST['subject_type']; // required
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
this is freecontact2formsettings:
<?php
$email_to = "myemailaddress#emailaddress.com"; // your email address
$email_subject = "Subject type"; // email subject line
if ($subjecttype_from="Maths")
{
$thankyou = "http://www.google.com";
}
else
{
$thankyou = "http://www.yahoo.com"; // thank you page
}
// if you update the question on the form -
// you need to update the questions answer below
$antispam_answer = "25";
?>
On the freecontact2formsetting file, i have set a condition that if the user selects Maths from the drop down menu, the thank you page is set to google.com, if however anything else is selected it goes to yahoo.com. Currently all redirects are going to google.com regardless, how do i make sure when the user selects anything but maths, it goes to yahoo.com?
You're assigning rather than evaluating, change your if statement to:
if ($subjecttype_from == "Maths")
You could also write it like this:
$thankyou = ($subjecttype_from == "Maths") ? 'http://www.google.com' : 'http://www.yahoo.com';
From looking at your code, $subjecttype_from isn't defined when your if statement is evaluated. Assign the variable before you include the file which makes the comparison, eg:
$subjecttype_from = $_POST['subject_type']; // required
include 'freecontact2formsettings.php';