Php 如何从下拉列表中获取值并插入MySQL工作台?
在我选择了下拉列表中的一项之后,所选选项不会显示在MySQL工作台(版本8)中 下面提供的代码(包括php代码)在我的名为Php 如何从下拉列表中获取值并插入MySQL工作台?,php,mysql,mysqli,mysql-workbench,Php,Mysql,Mysqli,Mysql Workbench,在我选择了下拉列表中的一项之后,所选选项不会显示在MySQL工作台(版本8)中 下面提供的代码(包括php代码)在我的名为crimenews和crimetypes的表中,还有许多其他列,但我的问题是所选选项没有显示在MySQL Workbench中 Connect.php <?php $server = "xxx.xxx.xxx.xxx"; //xxx=number $username = "xxx"; $password = "xxx";
crimenews
和crimetypes
的表中,还有许多其他列,但我的问题是所选选项没有显示在MySQL Workbench中
Connect.php
<?php
$server = "xxx.xxx.xxx.xxx"; //xxx=number
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
//Establish database connection
$conn = new mysqli($server, $username, $password, $dbname);
if($conn->connect_error)
{
die("Connection failed: ". $conn->connect_error);
}
?>
MySQL工作台中的crimetype表
crimetype_id|crime_type
------------|-----------
1 | A
2 | B
.
.
.
MySQL工作台中的crimenews表
这里是MySQL工作台(crimenews表)的预期结果
如何从
crimetype
表中获取crimetype中的值,并将其插入到crimenews类型中的crimenews
表中?您选择的名称是category
,在$\u POST
中,它作为类别。您必须更改它。..(其他列)
-请不要向我们显示伪代码,请向我们显示您的实际代码。插入数据库
您没有名为数据库
的表,我已经编辑并添加了更多代码,并进行了一些拼写检查,谢谢@脾气暴躁的克劳顿
//For adding news
$category = $_POST['category'];
$url = $_POST['url'];
$datetime = $_POST['datetime'];
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$sql = "INSERT INTO crimenews (crimenews_type, crimenews_url, crimenews_date, crimenews_locationLat, crimenews_locationLong) VALUES ('$category', '$url', '$datetime', '$lat', '$lng')";
if($conn->query($sql) === TRUE)
{
header("location: front.php");
}
else
{
echo "Error!";
}
crimetype_id|crime_type
------------|-----------
1 | A
2 | B
.
.
.
crimenews_id|crimenews_type|crimenews_url|crimenews_date|crimenews_locationLat|crimenews_locationLong
------------|--------------|-------------|--------------|---------------------|----------------------
1 | | | | |
2 | | | | |
.
.
.
crimenews_id|crimenews_type|crimenews_url|crimenews_date|crimenews_locationLat|crimenews_locationLong
------------|--------------|-------------|--------------|---------------------|----------------------
1 | A | | | |
2 | B | | | |
.
.
.