Php 无法将表单提交中的用户输入插入数据库。正在添加空行
我的表名是events..我的数据库名是admin_data.您可以帮助纠正它。 这是我的php文件:events.php。在表中,event_date和event_class在表中为0000,其他字段在行中为空Php 无法将表单提交中的用户输入插入数据库。正在添加空行,php,mysql,Php,Mysql,我的表名是events..我的数据库名是admin_data.您可以帮助纠正它。 这是我的php文件:events.php。在表中,event_date和event_class在表中为0000,其他字段在行中为空 <html> <head> <title>Events</title> </head> <body> <?php if(isset($_POST['save'])) { $dbhost = 'localhos
<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">
^^^^^^^^^^^^^^^^^
事件日期
^^^^^^^^^^^^^^^^^
现在表格正在递增..但是我在表格中输入的数据不在表格中。您需要在表格中为所有这4个字段添加name
属性。请参阅我的答案。对于事件描述,它不起作用。对于类,它仍然是000-00-0。对于事件描述
您有对于事件描述,它不起作用。我放置了下拉列表。如果我在表中选择它,则输入as000-00-00。同时,年份与年-月日期相反打印。我需要日期-月-年该表是递增。但是我在表单中给出的值没有输入到datbase中。错误是所有变量的未定义语法,因为event_类不起作用。我放置了下拉列表。如果我在表中选择,则其输入为000-00-00。同时,年份以年-月日期的形式反向打印。我需要日期-月-年