我的想法是填写HTML表单中的条目,然后将信息保存到数据库(phpmyadmin)。然后在谷歌地图上显示信息(导出)。
但由于语法和逻辑问题,它无法正常工作。
我的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页面在BackEnd上:
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>
但是当我提交表格时,我得到了:
错误:您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在“长,拉,开,关”附近使用VALUES(&#39;&#39;,&#39;&#39;,& #39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&# 39;,&#39;&#39;)&#39;在第1行
保存开始/结束时间的最佳HTML属性是什么:周,天。小时,分钟,秒?
答案 0 :(得分:0)
您应该在列名周围使用反引号(`)。像这样:
JLabel Resultat = new JLabel("Résultat : ", SwingConstants.CENTER);
建议使用反引号用于表名和列名,但在使用import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exercice4 extends JFrame {
private JTextField ZoneTxt, ZoneTxt2;
private JPanel CalculPanel;
private JLabel Resultat;
private JComboBox Op;
private JButton BCalcul;
private int cbselect = 0;
private double res;
final String[] operateur = { "+", "-", "*", "/" };
public Exercice4() {
super("Exercice 4");
JFrame FrameExercice4 = new JFrame();
JPanel CalculPanel = new JPanel();
ZoneTxt = new JTextField(10);
ZoneTxt2 = new JTextField(10);
final JComboBox Op = new JComboBox(operateur);
BCalcul = new JButton("Calculer");
BCalcul.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int cbselect = Op.getSelectedIndex();
if (cbselect == 0) {
res = (((Double.parseDouble(ZoneTxt.getText()))) + ((Double
.parseDouble(ZoneTxt2.getText()))));
System.out.println(res);
Resultat.setText("Résultat : " + String.valueOf(res));
}
if (cbselect == 1) {
// System.out.println(res1 - res2);
}
if (cbselect == 2) {
// System.out.println(res1 * res2);
}
if (cbselect == 3) {
// System.out.println(res1 / res2);
}
}
});
JLabel Resultat = new JLabel("Résultat : ", SwingConstants.CENTER);
FrameExercice4.setVisible(true);
FrameExercice4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FrameExercice4.setSize(500, 500);
FrameExercice4.add(CalculPanel);
CalculPanel.add(ZoneTxt);
CalculPanel.add(Op);
CalculPanel.add(ZoneTxt2);
CalculPanel.add(BCalcul);
CalculPanel.add(Resultat, BorderLayout.CENTER);
}
public static void main(String[] args) {
JFrame frame = new Exercice4();
}
}
等保留关键字时必须使用反对。
查看this discussion了解详情。
关于第二个问题,请查看HTML5 $sql = "INSERT INTO locations (`name`, `type`, `address`, `email`, `phone`, `long`, `lat`, `opening`, `closing`)
VALUES('$name', '$type', '$address', '$email', '$phone', '$long', '$lat', '$opening', '$closing')";
输入类型。请注意it is not supported by all browsers