下拉列表不起作用,只插入0

时间:2017-04-20 01:57:29

标签: php mysql

您好我从下拉菜单中插入代码时遇到问题。其余的值插入完全正常,但下拉列表中的值只是插入0。

HTML:

 <form action="send_registration.php" method="post">

    <p>

        <label for="username">Username:</label>

        <input type="text" name="username" id="username">

    </p>

    <p>

        <label for="password">password:</label>

        <input type="password" name="password" id="password">

    </p>

    <p>

        <label for="email">Email:</label>

        <input type="text" name="email" id="email">

    </p>

  <p>


<label for="countryID">Country:</label>
<select>
<option name="countryID" id="countryID" value="countryID" >
    <option value="1">"Andorra" </option>
    <option value="2">"United Arab Emirates" </option>
    <option value="3">"wont bore with the rest" </option>
</option>

</select>

    </p>
    <input type="submit" value="Submit">

</form>

PHP:

<?php

include('connection.php');
/* Attempt MySQL server connection. Assuming you are running MySQL

server with default setting (user 'root' with no password) */





// Check connection

if($conn === false){

    die("ERROR: Could not connect. " . mysqli_connect_error());

}



// Escape user inputs for security

$username = mysqli_real_escape_string($conn, $_REQUEST['username']);

$password = mysqli_real_escape_string($conn, $_REQUEST['password']);

$email = mysqli_real_escape_string($conn, $_REQUEST['email']);
$countryID = mysqli_real_escape_string($conn, $_REQUEST['countryID']);

 $encrypt_password = md5($password);

// attempt insert query execution

$sql = "INSERT INTO users (username, password, email, countryID) VALUES ('$username', '$encrypt_password', '$email',  '$countryID')";

if(mysqli_query($conn, $sql)){

    header("Location: login.php");

} else{

    echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);

}



// close connection

mysqli_close($conn);

?>

1 个答案:

答案 0 :(得分:0)

你有一个选项标签下拉列表的名称,它应该在select标签上,如此。

<select name="countryID" id="countryID">
  <option value="1">"Andorra" </option>
  <option value="2">"United Arab Emirates" </option>
  <option value="3">"wont bore with the rest" </option>
</select>