gpt4 book ai didi

php - 使用php将数据插入mysql

转载 作者:行者123 更新时间:2023-11-30 00:26:34 25 4
gpt4 key购买 nike

我在尝试将表单数据加载到数据库中时遇到了困难。我正在尝试使用以下 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>

我想知道是否有人可以就我做错的事情给我一些指导。我已经被这个问题困扰了几个小时,并且不知道我做错了什么。

编辑:我没有收到错误,但数据没有上传到数据库中。由于某种原因我的查询不起作用。

最佳答案

试试这个

     <?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'];

//**change code to below**
$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.";
}

}?>

链接 single quoted

注意:与双引号和定界语法不同,特殊字符的变量和转义序列在单引号字符串中出现时不会被扩展。

关于php - 使用php将数据插入mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22826507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com