rghayes Posted May 8, 2013 Author Share Posted May 8, 2013 Previous code didn't work. adding die(mysql()) returned this: No database selected But the first line of my code says to connect to one or return an error...... Link to comment https://forums.phpfreaks.com/topic/277706-checkboxes/page/2/#findComment-1429179 Share on other sites More sharing options...
Barand Posted May 8, 2013 Share Posted May 8, 2013 Do you think it may be something to to with creating a mysqli connection but using mysql_query()? Link to comment https://forums.phpfreaks.com/topic/277706-checkboxes/page/2/#findComment-1429181 Share on other sites More sharing options...
rghayes Posted May 9, 2013 Author Share Posted May 9, 2013 OK, so I tried it with mysql_query(). It does send data to the db, but no matter which ones or how many I choose, it only sends a portion to the db. Here is my updated code: <?php$con = mysql_connect("localhost","root","YES"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("charity_db", $con);if(isset($_POST["vote"])) {$vote = $_POST["vote"];}else {$vote=array();}for ($i="0"; $i<count($vote); $i++) {if(!is_numeric($vote[$i])) {$vote[$i]="";}if(empty($vote[$i])) {unset($vote[$i]);}}$vote = implode ("<>", $vote);$vote = "<>".$vote."";$sql = "INSERT INTO data_tbl (`id`, `choice`) VALUES (NULL, '$vote')";$res=mysql_query($sql) or die (mysql_error());echo $sql;?> Link to comment https://forums.phpfreaks.com/topic/277706-checkboxes/page/2/#findComment-1429222 Share on other sites More sharing options...
Barand Posted May 9, 2013 Share Posted May 9, 2013 if you use this code to check the POST array echo '<pre>',print_r($_POST['vote'], true),'</pre>'; you will see that only checked values are posted Link to comment https://forums.phpfreaks.com/topic/277706-checkboxes/page/2/#findComment-1429266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.