Jump to content

rghayes

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by rghayes

  1. 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; ?>
  2. 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......
  3. I still am still struggling with this but please check out my updated code. After some serious research I found this but I keep getting Fail to add test_value. if (!$db_conn = new mysqli('localhost', 'root', 'YES', 'charity_db')) { echo 'Could not connect to db<br />'; exit; } 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 ("Fail to add test_value"); $sql = "select id, choice from data_tbl limit 1"; $res=mysql_query($sql) or die ("Fail to get test"); $test = explode('<>',$pres[1]); for ($i="0"; $i<count($vote); $i++) { if(empty($vote[$i])) {unset($vote[$i]);} } ?>
  4. OK now it gave me this: update `poll_results` set `num_votes` = `num_votes` + 1 where candidate IN (TomJo,AlJac,AmyThom,ArthurBo,BillyMid,KarenMil)
  5. This is what was returned on submit: Notice: Undefined index: myvote in C:\xampp\htdocs\belltion\show_poll.php on line 2 Warning: array_map(): Argument #2 should be an array in C:\xampp\htdocs\belltion\show_poll.php on line 4 Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\belltion\show_poll.php on line 4 update `poll_results` set `num_votes` = `num_votes` + 1 where candidate IN ()
  6. Only one table with 2 columns. First column is the name of what is being voted for and the second column keeps up with the number of votes. This is what I think is giving me such a hard time, all I need to do is update the number of votes in the db not really add data.
  7. Didn't work, sends nothing to the db when multiple entries are chosen. works fine if only one is chose.
  8. Ok here is my PHP. I think my biggest problem now is I need to update the count in the db not really add anything <?php $vote=$_POST['vote']; $tstring = implode(',' , $vote); echo $tstring; $con = mysql_connect("localhost","root","YES"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("poll", $con); //insert to the table $sql="update poll_results set num_votes = num_votes + 1 where candidate = '$tstring'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "CheckBox value succesfully added"; mysql_close($con) ?>
  9. OK, my database just has entries for each choice represented by each check box and I need to keep up with how many times an item is voted on.
  10. That works but it shows all the checked values shoved together likethis. It still only inputs the last on chosen into the db.
  11. Trying now, but still not working I am using the an array as shown above and then $vote=$_REQUEST['myvote']; to request what has been checked. Is there a better way?
  12. I am designing a voting webpage where in users can choose multiple values and all are submitted to a mysql database. I am using checkboxes. I can get one value to go in great, but its the mutiple value thing that has me pulling my hair out. Can someone PLEASE help a beginner out??
×
×
  • 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.