无法将表单提交中的用户输入插入到database.empty行中

时间:2014-03-25 05:09:27

标签: php mysql

我的表名是events..my数据库名是admin_data.can帮助如何纠正它。 这是我的php文件:events.php .in table 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;
}

1 个答案:

答案 0 :(得分:0)

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

$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">
                                                               ^^^^^^^^^^^^^^^^^