简单的PHP表单不提交

时间:2014-03-09 01:14:22

标签: php mysql pdo mysqli innodb

页面似乎没有写入数据库。我有一种感觉,这可能是数据库错误,而不是表单提交本身。我找不到任何错误,我似乎无法弄清楚为什么数据库不接受我的参数。请参阅下面的代码和数据库结构。如果您需要更多信息,请与我们联系。

    <?php
session_name('shipshapeLogin');
session_set_cookie_params(2*7*24*60*60);
session_start();

define('INCLUDE_CHECK',true);

require('connect.php');
//require_once('business.php');

if(empty($_SESSION['id']))
{
    header("Location: index.php");
    exit;
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Ad Posting</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" type="text/css" href="advertise.css" />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script>
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  </script>
</head>
<body>
<div class="container">
<form action="" method="post" class="advertiseform">
<div>
<input class="field" type="text" name="business" id="business" disabled="disabled" placeholder="Business Name" value="<?php echo $_SESSION['username']?>"  required="true" />
</div>
<div>
<input class="field" type="text" name="title" id="title" placeholder="Title" value="" size="23" required="true" />
</div>
<div>
<textarea input class="field" type="textarea" name="ad" id="ad" placeholder="Body" required="true">
</textarea>
</div>
<div>
<input type="text" id="from" name="from" placeholder="Valid from:" required="true">
</div>
<div>
<input type="text" id="to" name="to" placeholder="To:" required="true">
</div>
<div>
<button type="button" id="clearbtn">Clear Advertisement</button>
<input type="submit" name="submit" value="Post Advertisement" class="submit" />
</div>
</form>
</div>

<?php


$business_name = $_POST['business'];
$title = $_POST['title'];
$body = $_POST['ad'];
//$valid_date= $_POST['from']." to ". $_POST['to'];
$fromDate = $_POST['from'];
$toDate = $_POST['to'];


$query = "INSERT INTO Businesses_ads ( business_name, title, from, to, body, posted) VALUES ( :business_name, :title, :from, :to, :body, NOW())";


    $query_params = array(

        ':business_name' => $business_name,
        ':title' => $title,
        ':from' => $fromDate,
        ':to' => $toDate,
        ':body' => $body,
    );

        try{

        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);

        }
        catch(PDOException $ex)
        {
            echo $ex;
        }

?>
</body>
</html>

enter image description here

1 个答案:

答案 0 :(得分:5)

tofromreserved words,必须用反引号包装

变化:

( business_name, title, from, to, body, posted)

为:

( business_name, title, `from`, `to`, body, posted)