Forum Moderators: coopster
if ( $newsletter > 0 ) {
$newsletter == "Yes";
}
else $newsletter == "No";
I have a tick box in a form which has a value of 1 if checked.... my submitted form calls a php file which inputs the form results into a mysql database...
basically I want the value of the checkbox to change to either yes or no bassed on whether it is ticked or not. why isn't the code above working? its just leaving a blank entry... my entire code is pasted below...
<?php
date_default_timezone_set('GMT+1');
if ( $newsletter > 0 ) {
$newsletter == "Yes";
}
else $newsletter == "No";
$sendto = "*****************";
$name = $_POST['name'];
$company = $_POST['company'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$interest = $_POST['interest'];
$newsletter = $_POST['newsletter'];
$date = date('M jS Y H:i');
header ("Location: **************");
mail( "$sendto", "*************",
"This is a lead from the form located on ************* the person would like infomation on the products listed below.\n\n".
"Date: $date\n".
"Name: $name\n".
"Company: $company\n".
"Country: $country\n".
"Phone: $phone\n".
"Email: $email\n".
"Products interested in: $interest\n".
"Add to newsletter?: $newsletter\n");
$Query="Insert into BUY (Date,Name,Company,Country,TelNumber,EmailAddress,InterestedIn,Newsletter,ServerAddress)";
$Query2=" values ('".$date."','".$name."','".$company."','".$country."','".$phone."','".$email."','".$interest."','".$newsletter."','".$_SERVER['REMOTE_ADDR']."')";
$Query=$Query.$Query2;
echo $Query;
$conn1 = new mysqli("**************", "******", "*****", "*******");
$result1 = $conn1->query($Query);
?>
I'm no PHP expert, but I think you are using == incorrectly, instead use a single =
if ( $newsletter > 0 ) {
$newsletter = "Yes";
}
else $newsletter = "No";
== is for comparisons and = sets a variable
HTH
JB
if ( $newsletter > 0 ) {
$newsletter == "Yes";
}
else $newsletter == "No";$sendto = "*****************";
$name = $_POST['name'];
$company = $_POST['company'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$interest = $_POST['interest'];
$newsletter = $_POST['newsletter'];
I'm a little confused here, you're checking whether $newsletter is greater than zero BEFORE you get the variable? If so, $newsletter is always going to be whatever the POST value is since that's after the if/else check.