gibbo1715 Posted December 2, 2009 Share Posted December 2, 2009 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 More sharing options...
Mchl Posted December 2, 2009 Share Posted December 2, 2009 $data_to_use=$read .','.$enter; Link to comment https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/#findComment-969787 Share on other sites More sharing options...
gibbo1715 Posted December 2, 2009 Author Share Posted December 2, 2009 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> Link to comment https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/#findComment-969794 Share on other sites More sharing options...
severndigital Posted December 2, 2009 Share Posted December 2, 2009 mysql using the , to separate fields in the sql query you will have to use addslashes() to make mysql ignore the comma Link to comment https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/#findComment-969810 Share on other sites More sharing options...
gibbo1715 Posted December 2, 2009 Author Share Posted December 2, 2009 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 Link to comment https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/#findComment-969823 Share on other sites More sharing options...
severndigital Posted December 2, 2009 Share Posted December 2, 2009 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()); Link to comment https://forums.phpfreaks.com/topic/183740-merging-two-with-a-comma-between-them/#findComment-969837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.