无法插入数据库

时间:2016-02-19 11:23:24

标签: php mysql

我试图在表格中插入联系我们的详细信息,但我不能,我试过但我仍然不能,为什么?我做错了什么?

任何帮助都会有很大的帮助,我尝试过以其他形式做的事情很好,而且这些数据还没有通过

HTML

     <div class="wrap-embed-contact-form">
    <form name="testing122" action="post.php" method="post" class="embed-     contact-form" >
        <div class="form-heading">Contact Us</div>
         <div class="form-sub-heading">Please, fill in the form to get in touch!</div>
    <hr>
    <div class="form-message hide">
        Your message has been sent successfully!
    </div>
    <div class="form-content">
        <div class="group">
            <label for="name" class="empty"></label>
            <div><input id="name" name="name" placeholder="Your Name" class="form-control"></div>
        </div>
        <div class="group">
            <label for="email" class="empty"></label>
            <div><input type="email" name="email" placeholder="Your Email" class="form-control"></div>
        </div>
        <div class="group">
            <label for="query-type">Query type</label>
            <div>
                <select id="query-type" name="query-type" class="form-control">
                    <option value="General Query">General Query</option>
                    <option value="Presale">Courses Query</option>
                    <option value="Technical">Addmission</option>
                    <option value="Others">Others</option>
                </select>
            </div>
        </div>
        <div class="group">
            <label for="message" class="empty"></label>
            <div><textarea id="message" name="message" placeholder="Your Message" class="form-control" rows="5"></textarea></div>
        </div>
        <div class="group">
            <label class="empty"></label>
            <div><button class="btn-submit" type="submit">Send Message</button></div>
        </div>
    </div>
    <a class="btn-show-contact" href="#contact"><img src="<?php echo $path; ?>img/btn_contact.png"></a>
</form>

post.php中

       <?php
  $con = mysql_connect("localhost","root","");
  if (!$con)
  {
 die('Could not connect: ' . mysql_error());
   }

  mysql_select_db("aptech", $con);

 $sql="INSERT INTO contact (post_name,post_email,post_type,message)
 VALUES
 ('$_POST[name]','$_POST[email]','$_POST[query-type]','$_POST[message]')";

 mysql_close($con);
?>

4 个答案:

答案 0 :(得分:4)

您忘记运行查询。

  mysql_select_db("aptech", $con);

 $sql="INSERT INTO contact (post_name,post_email,post_type,message)
 VALUES
 ('$_POST[name]','$_POST[email]','$_POST[query-type]','$_POST[message]')";

 mysql_query($sql); // <---------- You forgot this!

 mysql_close($con);

答案 1 :(得分:0)

       $con = mysql_connect("localhost","root","");
          if (!$con)
          {
                die('Could not connect: ' . mysql_error());
          }

          mysql_select_db("aptech", $con);   

      if(isset($_POST) && !empty($_POST))
      {

        $name=$_POST['name'];
        $email=$_POST['email'];
        $querytype=$_POST['query-type'];
        $message=$_POST['message'];


        $sql="INSERT INTO contact (post_name,post_email,post_type,message)
         VALUES
         ('$name','$email','$querytype','$message')";
        mysql_query($sql);
      }

答案 2 :(得分:0)

请使用以下代码:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
        die('Could not connect: ' . mysql_error());
}

mysql_select_db("aptech", $con);

if(isset($_POST) && !empty($_POST))
{
    $sql="INSERT INTO contact (post_name,post_email,post_type,message)
    VALUES
    ('{$_POST[name]}','{$_POST[email]}','{$_POST[query-type]}','{$_POST[message]}')";
    mysql_query($sql); // Run query
    echo mysql_errno($con) . ": " . mysql_error($con) . "\n"; // Get errors
    mysql_close($con);
}

    ?>

答案 3 :(得分:0)

谢谢大家,问题在于CSS并嵌入了东西,现在已经解决了:D