在php中添加Span
这部分工作正常
<select id="selectbasic" name="country" class="form-control">
<?php
$mysqli = new mysqli("localhost", "root", "", "gocall");
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($mysqli, "SELECT country_name FROM country ")) {
$row= mysqli_num_rows($result);
while ($row= mysqli_fetch_array($result)) {
$id=$row[0];
echo" <option value=\"FR\">$id</option>";
}
}
?>
</select>
************************************************************************
将组合框保存在数据库中
这是错误
<?php
if (isset($_POST['addcustomer'])) {
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$country=$_POST['country'];
$mysqli = new mysqli("localhost", "root", "", "db1");
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}
$req="INSERT INTO customer
VALUES (NULL,'$name','$lastname','$email','$password',$country)";
$mysqli->query($req);
$mysqli->close();
}
?>
答案 0 :(得分:0)
<?php
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
if (isset($_POST['addcustomer']))
{
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$country=$_POST['country'];
$mysqli = new mysqli("localhost", "root", "", "db1");
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}
$req="INSERT INTO customer VALUES (NULL,'$name','$lastname','$email','$password','$country')";
$mysqli->query($req);
$mysqli->close();
}
?>
答案 1 :(得分:-1)
你的下拉应该是;
<select id="selectbasic" name="country" class="form-control">
<?php
$mysqli = new mysqli("localhost", "root", "", "gocall");
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($mysqli, "SELECT country_id,country_name FROM country ")) {
$row= mysqli_num_rows($result);
while ($row= mysqli_fetch_array($result)) {
$id=$row['country_id'];
$country_name=$row['country_name'];
echo" <option value='$id'> $country_name </option>";
}
}
?>
</select>