how to save with a select in the database?

0

I need that when you select an option and click on the save button save me and my database but not how to program the php part.

<!DOCTYPE html>
<html>
<head>
    <title>Prueba Select</title>
</head>
<body>
    <center>
        <select name="users" onchange="showUser(this.value)">
          <option value="">Select a person:</option>
          <option value="1">Peter </option>
          <option value="2">Lois </option>
          <option value="3">Joseph </option>
          <option value="4">Glenn</option>
         </select>

    <input style="border-radius: 8px" type="submit" name="Guardar" value="Guardar">

    </center>   
</body>
</html>


<?php
$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','admin123','database');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table>
        <tr>
        <th>Firstname</th>
        </tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['FirstName'] . "</td>";
    echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
    
asked by Cristian Antonio Trujillo Gris 05.04.2018 в 16:06
source

1 answer

2

Look at your select has as name users

<select name="users" onchange="showUser(this.value)">

Also in your php code you have $q = intval($_GET['q']) and it should be like that

$q = intval($_GET['users']);
  

You also have to add more things to your code since only   you are listing elements, at no time do I see that you keep.

    
answered by 05.04.2018 в 16:20