Forum Moderators: coopster

Message Too Old, No Replies

I can't even get the basics. please help!

         

wardy83

9:13 am on Aug 7, 2008 (gmt 0)

10+ Year Member



Ok.... so If you can have a look at this code for me.

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

?>

johnblack

10:07 am on Aug 7, 2008 (gmt 0)



Hi,

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

StoutFiles

12:32 pm on Aug 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

wardy83

1:40 pm on Aug 7, 2008 (gmt 0)

10+ Year Member



hi there i did get it working....

thanks for your help both!

I moved it below my variable declarations and changed the == for a single =.

cheers lads!