php - Submitting random string from an array, submits the string after echoed string -
every time click submit name of element i'm voting on changes element shows after current echoed element when entered database. suggestions on how fix this? can't seem figure out.
lets echo shows example2 on value in form. click example2 example1 gets saved in database. i'm not sure how fix this. help.
here's code:
the array setup i'm using:
$array = array("example1","example2","example3"); $random = $array; shuffle($random); <?php echo array_pop($random);?>
php: action
i'm using post method in form.
$mysqli = new mysqli("", "", "", ""); if ($mysqli->connect_error) { echo "failed connect mysql: (" . $mysqli->connect_error . ") " . $mysqli->connect_error; } if (!$mysqli->query("insert table(id, name, votes) values (id, '".$random."', '".$votes."')")) { echo "multi-insert failed: (" . $mysqli->errno . ") " . $mysqli->error; }
to make question clear, believe want following:
- pick random element array.
- show in webpage.
- insert in database
so,
$array = array("example1","example2","example3"); shuffle($array); $element = array_pop($array); echo $element;
then insert $element
in database.
above wish. rest of code doesn't make sense.
Comments
Post a Comment