【发布时间】:2014-05-14 14:59:54
【问题描述】:
我在尝试将表单数据加载到我的数据库时遇到了困难。 我正在尝试使用以下 php 脚本输入剧院信息。
<?php
require('connect.php');
if (isset($_POST['theatre_name']) && isset($_POST['website'])){
$theatre_name = $_POST['theatre_name'];
$phone_number = $_POST['phone_number'];
$website = $_POST['website'];
$num_screens = $_POST['num_screens'];
$address = $_POST['address'];
$city = $_POST['city'];
$queryd = "INSERT INTO `Theatres` (theatre_name, phone_number, website,
num_screens, address, city)
VALUES ('$theatre_name', '$phone_number', '$website', '$num_screens',
'$address', '$city')";
$result = mysql_query($queryd);
if($result){
$msg = "Theatre created.";
}
}
?>
以下是我的html代码:
<!DOCTYPE html>
<html>
<body>
<!-- Form for creating theaters -->
<div class="register-form">
<?php
if(isset($msg) & !empty($msg)){
echo $msg;
}
?>
<form action="theatredb.php" method="POST">
<p><label>Theater Name : </label>
<input type = "text" name= "theatre_name" placeholder= "Theater Name" /></p>
<p><label>Phone Number : </label>
<input type = "text" name= "phone_number" placeholder="Phone Number" /></p>
<p><label>Website : </label>
<input type="text" name= "website" placeholder ="Website" /></p>
<p><label> Number of Screens : </label>
<input type= "text" name="num_screens" placeholder ="Number of screens" /></p>
<p><label>Address : </label>
<input type="text" name="address" placeholder="Address" /></p>
<p><label>City : </label>
<input type="text" name="city" required placeholder="City Name" /></p>
<input class="btn register" type="submit" name="submit" value="done" />
</form>
</div>
</body>
</html>
我想知道是否有人可以就我做错的事情给我一些指导。我已经被这个问题困扰了几个小时,不知道我做错了什么。
编辑:我没有得到一个错误的说法,但数据没有上传到数据库中。由于某种原因,我的查询不起作用。
【问题讨论】:
-
你得到什么错误?您应该使用
mysql_error()检查代码中的错误。 -
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果您选择 PDO,here is a good tutorial。 你也对SQL injections敞开心扉
标签: php html mysql database forms