user3324374
user3324374

Reputation: 25

Can't insert into database

I am trying to insert the contact us details in the table but i can't ,I tried but i still can't ,Why ? I am doing something wrong?

Any help would be a great help ,I tried doing in other form and it was fine and this data isn't going through

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);
?>

Upvotes: 0

Views: 59

Answers (4)

user3324374
user3324374

Reputation: 25

Thank you everyone ,The issue was with CSS and embed thing and now its solved :D

Upvotes: 0

Milan
Milan

Reputation: 631

Please Use below code :

<?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);
}

    ?>

Upvotes: 0

safin chacko
safin chacko

Reputation: 1390

       $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);
      }

Upvotes: 0

isnisn
isnisn

Reputation: 254

You forgot to run the query.

  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);

Upvotes: 4

Related Questions