dimanche 28 mai 2017

a problrm when i turn a html form inputs into php array

My html file contains the following form

<form action="action.php" method="get">
First name:<br>
<input type="text" name="name[]" /><br>
Second name:<br>
<input type="text" name="name[]" /><br>
Third name:<br>
<input type="text" name="name[]" /><br>
Forth name:<br>
<input type="text" name="name[]" /><br>
<input type="submit" value="submit">
</form>

and I want the output to be one random value of the inputs , so my action.php looks like

<?php

    $output = $_POST['name'];

 $key = array_rand($output);
echo $output[$key];

                   ?>

but this doesn't work and gives me the following

Notice: Undefined index: name in C:\xampp\htdocs\myfiles\action.php on line 8

Warning: array_rand() expects parameter 1 to be array, null given in C:\xampp\htdocs\myfiles\action.php on line 10

can any one help please?




Aucun commentaire:

Enregistrer un commentaire