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...... Quote Link to comment 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()? Quote Link to comment 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;?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.