manoDydayasdfcdxc
New Member
I am still new to PHP and trying to create an interactive voting system. I used 2 arrays that hold names in a string. I used \[code\]<?php$array(...,...);$array2(...,...);$random = $array; $random2 = $array2; shuffle($random); shuffle($random2);?>\[/code\]to output name randomly. I then created a form with \[code\]<form action="action.php" method="post"><input type="button" onclick="window.location.reload()" value="http://stackoverflow.com/questions/15735697/<?php echo array_pop($random);?>" name="name" /></form><form action="action.php" method="post"><input type="button" onclick="window.location.reload()" value="http://stackoverflow.com/questions/15735697/<?php echo array_pop($random2);?>" name="haventseen" /></form>\[/code\]At this point all the names show up randomly in a button to click, and when clicked, 2 new ones show up. The problem I am having is storing the information in the database. Since it is a voting system, I'd like to store them in DB and each time a user clicks on the button +1 is added to that particular name. And when the "haventseen" button is clicked +1 to that name in the button above in the haventseen row. This is how my table is set up:It is a MySQL 5.0 database.\[code\]id INT NOT NULL AUTO_INCREMENT PRIMARY KEY (id)name VARCHAR(80)vote INT(11)haventseen INT(11)\[/code\]Here is my code so far.\[code\]<?php $dbname = "db_name"; $con=mysql_connect("local","root","pass"); if(!$con) { die ('Could not connect: '.mysql_error()); } echo ('Connected');mysql_select_db($dbname, $con);$sql="INSERT INTO `table_name` (`name`) VALUES ('{$_POST['name']}')";$sql="INSERT INTO `table_name` (`name`) VALUES ('{$_POST['haventseen']}')";if (!mysql_query($sql, $con)){ die('Error: ' . mysql_error());}?>\[/code\]I'm not really sure where to go from here. But this setup isn't putting anything into the database (I changed some names for this post) even when all the names are correct. Some sample code would be really nice! But if its too much trouble please talk me through some steps I can take.