Jump to content

merging two $ with a comma between them


gibbo1715

Recommended Posts

All

 

I am trying to chech the value of two check boxes and then merge the results for if they are true of false as follows

 

true = 1

false = 0

 

$read=(@$_POST['understood']=='1')? $_POST['understood']:'0';
$enter=(@$_POST['optIn']=='1')? $_POST['optIn']:'0';

$data_to_use=$read ','$enter;
$query="INSERT INTO checkbox (mydata) VALUES ('$data_to_use')";
} 

 

i believe my ewrror is here  $data_to_use=$read ','$enter;

 

can someone tell me how to link this together so i get 1,1 or 1, 0 etc as the output to the db

 

thanks

 

gibbo

Link to comment
https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/
Share on other sites

thanks

 

i no longer get an error but nothing is being added to my database

 

can anyone see my error please

 

thanks

 

gibbo

 

<? 
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form 
?> 
<html> 
<head> 
<title>Personal INFO</title> 
</head> 
<body> 
<form method="post" action="<?php echo $PHP_SELF;?>"> 
<input type="checkbox" name="understood" value="true" />
<input type="checkbox" name="optIn" value="true" />
<input type="submit" value="sign up" />
</form>
<? 
} else { 
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error()); 
mysql_select_db("sharedDB"); 

$read=(@$_POST['understood']=='1')? $_POST['understood']:'0';
$enter=(@$_POST['optIn']=='1')? $_POST['optIn']:'0';

$data_to_use=$read .','.$enter;
$query="INSERT INTO checkbox (mydata) VALUES ('$data_to_use')";
echo 'Test <br>';
echo $data_to_use;
} 
?> 
</body> 
</html>

Ok thats another one i needed to learn but I have tries using a letter and it still doesnt write to my database and even if my check boxes are checked i get 0 's

 

any ideas or if anyone can point me to a better way of getting true or false from checkboxes?

 

thanks

 

gibbo

what is the type of field you are trying to insert the information into?

if the field type is an int or enum or something it will be error out because of the comma

 

also where is your mysql_query() line? does that have an mysql_error() with it?

 

it should look something like this.

$query "INSERT INTO table (field) VALUES ('value')";
$push  = mysql_query($query) or die(mysql_error());

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.