gpt4 book ai didi

php - 无法将表单提交中的用户输入插入数据库。正在添加空行

转载 作者:行者123 更新时间:2023-11-30 00:29:27 24 4
gpt4 key购买 nike

我的表名称是 events..我的数据库名称是 admin_data.可以帮助如何纠正它。这是我的 php 文件:events.php 。表中的 event_date 和 event_class 为 0000,其他字段在行中为空。

<html>
<head>
<title>Events</title>
</head>
<body>
<?php
if(isset($_POST['save']))
{
$dbhost = 'localhost';
$dbuser = 'admin';
$dbpass = 'admin@123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() )
{
$Event_Title = addslashes ($_POST['Event_Title']);
$Event_Date = addslashes ($_POST['Event_Date']);
$Event_Description = addslashes ($_POST['Event_Description']);
$Event_Class = addslashes ($_POST['Event_Class']);
}
else
{
$Event_Title = $_POST['Event_Title'];
$Event_Date = $_POST['Event_Date'];
$Event_Description = $_POST['Event_Description'];
$Event_Class = $_POST['Event_Class'];
}

$Event_Date = $_POST['Event_Date'];


$sql = "INSERT INTO events (Event_Title,Event_Date,Event_Description,Event_Class) VALUES ('$Event_Title','$Event_Date','$Event_Description','$Event_Class')";
mysql_select_db('admin_data');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<!DOCTYPE HTML>

<head>
<title>EVENTS</title>
<link rel="stylesheet" type="text/css" href="css/events.css">
<script src="js/notification.js"> </script>
</head>
<body>
<div>
<div class="layout">
<div class="heading"></div>
<div class="img1"></div>
<div class="menu">
<div>

<form method="post" action="<?php $_PHP_SELF ?>">
<label class="Event_Title">EVENT TITLE</label><input type="text" placeholder="EVENT TITLE" id="Event_Title">
<label class="Event_Date">EVENT DATE</label><input type="date" placeholder="EVENTS DATE" id="Event_Date">
<label class="Event_Description">EVENT DESCRIPTION</label><textarea name="Name" id="Event_Description" rows="8" cols="40"></textarea>
<label class="Event_Class1">GRADE</label>
<select class="Event_Class">
<option>KG1</option><option>KG2</option><option>A</option><option>B</option>
<option>C</option><option>D</option><option>E</option>
<option>F</option><option>G</option><option>H</option><option>I</option><option>J</option><option>K</option>
</select>
<input type="submit" ' name="save" id="save" value="Save">

<input type="reset" button onclick="javascript:eraseText() name="reset" id="reset" value="Reset">

</form>
</div>
<div class="img2"></div>
</div>
</div>
<?php
}
?>
</body>
</html>


here is my css code:events.php





.layout
{
height:600px;
width:1300px;
background-color:gray;
position:relative;
}
.heading
{
height:55px;
width:1200px;
position:relative;
float:left;
left:40px;
background-color: white;
top:10px;
background-image: url("../images/logo.png");
background-size: 300px;
}
.menu
{
position:relative;
float:left;
height: 500px;
width:500px;
background-color:white;
left: 140px;top:20px;
}
.img1
{
background-image: url("../images/images.jpg");
float: left;
height: 192px;
left: 63px;
position: relative;
top: 119px;
width: 258px;
}
.Event_Title
{
position: relative;
top: 0px;
left: 0px;
}
#Event_Title
{
position: relative;
left: 15px;
}

.Event_Date
{
position: relative;
top: 50px;
left: -255px;
}
#Event_Date
{
position: relative;
top: 20px;
left: 110px;
}
.Event_Class
{
top: -170px;
position: relative;
left: -50px;
}
.Event_Class1
{
position: relative;
top: -169px;
left: -30px;
}
.Event_Description
{
position: relative;
top: 180px;
left: -159px;
}
#Event_Description
{
position: relative;
top: 180px;
left: 90px;
}

#save
{
position: relative;
top: 216px;
left: 100px;
}
#reset
{
position: relative;
float: left;

width: 60px;
left: 295px;
top: 216px;
}
.img2 {
background-image: url("../images/images (1).jpg");

float: left;
height: 192px;
left: 590px;
position: relative;
top: -120px;
width: 258px;
}

最佳答案

像这样重写您的查询...

$sql = "INSERT INTO events (`Event_Title`,`Event_Date`,`Event_Description`,`Event_Class`) VALUES ('$Event_Title','$Event_Date','$Event_Description','$Event_Class')";

为什么它对你不起作用?

  • 您的串联不正确。
  • 您忘记正确引用变量。
  • 您忘记在变量之间添加逗号。

name 属性添加到您的所有字段...

<label class="Event_Date">EVENT DATE</label><input type="date" name="Event_Date"  placeholder="EVENTS DATE" id="Event_Date">
^^^^^^^^^^^^^^^^^

关于php - 无法将表单提交中的用户输入插入数据库。正在添加空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22625877/

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