HTML 表单 > SQL > Google 地图显示 - 语法 + 逻辑
HTML Form > SQL > Google Map Display - Syntax + Logic
我的想法是在 HTML 表单中填写条目,然后将信息保存到数据库 (phpmyadmin)。然后在 google 地图(导出)上显示信息。
但由于语法和逻辑问题,它无法正常工作。
我的HTML表格:
<html>
<head></head>
<body>
<form method="POST" action="../BackEnd/ShopSetup.php" name="Setup">
<td>Name</td>
<td>
<input type="text" name="name"></td>
</tr>
<tr>
<td>type</td>
<td>
<input type="varchar" name="type"></td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address"></td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="email" name="email"></td>
</tr>
<tr>
<td>Phone Number</td>
<td>
<input type="varchar" name="phone"></td>
</tr>
<tr>
<td>longitude</td>
<td>
<input type="float" name="long"></td>
</tr>
<tr>
<td>latitude</td>
<td>
<input type="float" name="lat"></td>
</tr>
<tr>
<td>Opening Hour</td>
<td>
<input type="varchar" name="opening"></td>
</tr>
<tr>
<td>Closing Hour</td>
<td>
<input type="varchar" name="closing"></td>
</tr>
<tr>
<td>
<input id="button" type="submit" name="submit" value="Setup"></td>
</tr>
<tr></tr>
</form>
</body>
</html>
我的 PHP 后端页面:
ShopSetup.php
<?php
include ("../Connections/Connection.php");
if (isset($_POST["submit"]))
{
$name = $_POST["name"];
$type = $_POST["type"];
$address = $_POST["address"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$long = $_POST["long"];
$lat = $_POST["lat"];
$opening = $_POST["opening"];
$closing = $_POST["closing"];
$sql = "INSERT INTO locations (name, type, address, email, phone, long, lat, opening, closing)
VALUES('$name', '$type', '$address', '$email', '$phone', '$long', '$lat', '$opening', '$closing')";
$query = mysql_query($sql);
if (!$query)
{
die ("Error : " . mysql_error());
}
if(empty($name) || empty($type) || empty($address) || empty($email) || empty($phone) || empty($long) || empty($lat) || empty($opening) || empty($closing))
{
echo "You did not fill out the required fields.";
die(); // Note this
}
echo "<center></center>";
}
?>
<h1> Your order is complete!</h1>
<p class="intro-text">You will see your shop on the map soon<br></p>
<center>
<h3> <a href="../index.php"> go to home page </a></h3>
</center>
但是当我提交表单时,我得到:
Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long, lat, opening, closing) VALUES('', '', '', '', '', '', '', '', '')' at line 1
什么是最好的 HTML 属性保存 opening/closing 次:周、天。时、分、秒?
您应该在列名周围使用反引号 (`)。像这样:
$sql = "INSERT INTO locations (`name`, `type`, `address`, `email`, `phone`, `long`, `lat`, `opening`, `closing`)
VALUES('$name', '$type', '$address', '$email', '$phone', '$long', '$lat', '$opening', '$closing')";
建议 table 和列名使用反引号,但在使用 long
.
等保留关键字时必须使用反引号
查看 this discussion 了解更多信息。
关于您的第二个问题,请查看 HTML5 datetime
输入类型。请注意 it is not supported by all browsers
我的想法是在 HTML 表单中填写条目,然后将信息保存到数据库 (phpmyadmin)。然后在 google 地图(导出)上显示信息。
但由于语法和逻辑问题,它无法正常工作。
我的HTML表格:
<html>
<head></head>
<body>
<form method="POST" action="../BackEnd/ShopSetup.php" name="Setup">
<td>Name</td>
<td>
<input type="text" name="name"></td>
</tr>
<tr>
<td>type</td>
<td>
<input type="varchar" name="type"></td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address"></td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="email" name="email"></td>
</tr>
<tr>
<td>Phone Number</td>
<td>
<input type="varchar" name="phone"></td>
</tr>
<tr>
<td>longitude</td>
<td>
<input type="float" name="long"></td>
</tr>
<tr>
<td>latitude</td>
<td>
<input type="float" name="lat"></td>
</tr>
<tr>
<td>Opening Hour</td>
<td>
<input type="varchar" name="opening"></td>
</tr>
<tr>
<td>Closing Hour</td>
<td>
<input type="varchar" name="closing"></td>
</tr>
<tr>
<td>
<input id="button" type="submit" name="submit" value="Setup"></td>
</tr>
<tr></tr>
</form>
</body>
</html>
我的 PHP 后端页面:
ShopSetup.php
<?php include ("../Connections/Connection.php"); if (isset($_POST["submit"])) { $name = $_POST["name"]; $type = $_POST["type"]; $address = $_POST["address"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $long = $_POST["long"]; $lat = $_POST["lat"]; $opening = $_POST["opening"]; $closing = $_POST["closing"]; $sql = "INSERT INTO locations (name, type, address, email, phone, long, lat, opening, closing) VALUES('$name', '$type', '$address', '$email', '$phone', '$long', '$lat', '$opening', '$closing')"; $query = mysql_query($sql); if (!$query) { die ("Error : " . mysql_error()); } if(empty($name) || empty($type) || empty($address) || empty($email) || empty($phone) || empty($long) || empty($lat) || empty($opening) || empty($closing)) { echo "You did not fill out the required fields."; die(); // Note this } echo "<center></center>"; } ?> <h1> Your order is complete!</h1> <p class="intro-text">You will see your shop on the map soon<br></p> <center> <h3> <a href="../index.php"> go to home page </a></h3> </center>
但是当我提交表单时,我得到:
Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long, lat, opening, closing) VALUES('', '', '', '', '', '', '', '', '')' at line 1
什么是最好的 HTML 属性保存 opening/closing 次:周、天。时、分、秒?
您应该在列名周围使用反引号 (`)。像这样:
$sql = "INSERT INTO locations (`name`, `type`, `address`, `email`, `phone`, `long`, `lat`, `opening`, `closing`)
VALUES('$name', '$type', '$address', '$email', '$phone', '$long', '$lat', '$opening', '$closing')";
建议 table 和列名使用反引号,但在使用 long
.
查看 this discussion 了解更多信息。
关于您的第二个问题,请查看 HTML5 datetime
输入类型。请注意 it is not supported by all browsers