【发布时间】:2019-08-27 15:03:24
【问题描述】:
在我选择下拉列表中的一项后,所选选项不会显示在 MySQL Workbench(版本 8)中。
下面提供的代码(包括 php 代码)在我的名为 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);
}
?>
Front.php (主页)
已经包含 connect.php
<form method="post" action="add.php"><center style="color: #FFFFC9 ; font-family: Arial">
<b>Category: </b>
<select name="catagory">
<?php
$type = "SELECT crime_type FROM crimetypes";
$qry = mysqli_query($conn,$type);
while($fin = mysqli_fetch_assoc($qry))
{
?> <option value="<?php echo($fin["crime_type"]);?>"><?php echo($fin["crime_type"]);?></option>
<?php
}
?>
</select>
<b>URL: </b> <input type="url" name="url" placeholder="URL (www.)"><br><br>
<b>Date: </b> <input type="datetime-local" name="datetime"><br><br>
<b>Latitude: </b> <input type="text" name="lat" placeholder="Latitude"><br><br>
<b>Longitude: </b> <input type="text" name="lng" placeholder="Longitude"><br><br>
<input type="submit" class="btn btn-success" value="Add"> //Submit button
</form>
添加.php
已经包含 connect.php
//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!";
}
MySQL Workbench 中的犯罪类型表
crimetype_id|crime_type
------------|-----------
1 | A
2 | B
.
.
.
MySQL Workbench 中的犯罪新闻表 (这确实发生了)
crimenews_id|crimenews_type|crimenews_url|crimenews_date|crimenews_locationLat|crimenews_locationLong
------------|--------------|-------------|--------------|---------------------|----------------------
1 | | | | |
2 | | | | |
.
.
.
这是 MySQL Workbench 中的预期结果(犯罪新闻表)
crimenews_id|crimenews_type|crimenews_url|crimenews_date|crimenews_locationLat|crimenews_locationLong
------------|--------------|-------------|--------------|---------------------|----------------------
1 | A | | | |
2 | B | | | |
.
.
.
如何从crimetypes表中获取crime_type中的值并插入到crimenews_type的crimenews表中?
【问题讨论】:
-
...(other columns)- 请不要向我们显示伪代码,向我们显示您的实际代码。 -
INSERT INTO database您没有名为database的表 -
我已经编辑并添加了更多代码并进行了一些拼写检查,谢谢。 @GrumpyCrouton
标签: php mysql mysqli mysql-workbench