-2

i want to process my comment that is contain name, email and message to database named "comment" but it cant. i really sure that my database name in phpmyadmin is same as in prosescomment.php. please help

this is my form

<form action="prosescomment.php" method="POST"  id="form" >
          <div class="success_wrapper">
            <div class="success">Contact form submitted!<br>
              <strong>We will be in touch soon.</strong> </div>
          </div>
          <fieldset>
              <input type="text" name="nama" placeholder="Name:">
              <br class="clear">
              <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span>
            <label class="email">
              <input type="text" name="email" placeholder="E-mail:">
              <br class="clear">
              <span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
            <label class="message">
              <textarea type="text" name="message" placeholder="Message"></textarea>
              <br class="clear">
              <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
            <div class="clear"></div>
            <div class="btns"><a data-type="submit" class="link1">Send</a>
              <div class="clear"></div>
            </div>
          </fieldset>
        </form>

this is my prosescomment.php

<?php 
    include "connection.php";

    $nama = $_POST['nama'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $query = "INSERT  INTO comment VALUES ('$nama', '$email', '$comment')";
    $result = mysql_query($query);

    if ($query) {
        header("location:index.html");
    }
    else{
        mysql_error();
    }
 ?>

this is my id form

#form {
padding-top: 6px;
}

#form input {
    color:#39596e;
     border: 1px solid #3c7f9f;
     padding: 4px 12px 9px;
    background-color: white;

    float:left;
    font: 13px/18px  Arial, Helvetica, sans-serif;
    box-sizing: border-box;
    -moz-box-sizing: border-box; /*Firefox 1-3*/
    -webkit-box-sizing: border-box; /* Safari */
}

#form textarea {
    color:#39596e;
    height: 170px;
    overflow: auto;
    background-color: white;
     border: 1px solid #3c7f9f;
     padding: 12px 12px 9px;
    width: 100%;
    position: relative;
    resize:none;
    box-sizing: border-box;
    -moz-box-sizing: border-box; /*Firefox 1-3*/
    -webkit-box-sizing: border-box; /* Safari */
    float:left;
    font: 13px/18px  Arial, Helvetica, sans-serif;
    margin: 0;

}
#form label {
    position:relative;
    display: block;
    min-height: 51px;
    width: 185px;
    float: left;
}

.email {
    padding-top: 10px;
}

#form .error, #form .empty {
    color: #FF0000;
    display: none;
    font-size: 11px;
    line-height:14px;
    width:auto;
    position: absolute;
    z-index: 999;
    right: 5px;
    bottom: 4px;
    float:left;
}

#form .message .error, #form .message .empty {
    bottom: -16px;
}

#form .error-empty {
    display:none;
    float:left;
}

.btns {
    position:relative;
    padding-top: 20px;
    text-align: center;

}


.btns a {
    display: inline-block;
    font-size: 19px;
    line-height: 18px;
    background-color: #f17c72;
    border: 1px solid #b76058;
    min-width: 107px;
    padding: 5px 10px 6px;
    color: #fff;
    cursor: pointer;
}

.btns a:hover {
    background-color: #c2e8f4;
    border-color: #3c7f9f;
    color: #39596e;
}

#form .message {
    width: 100%;
}

#form .btns span {
    display: inline-block;
    width: 13px;
}


.message br {
    height: 0;
    line-height: 0;
}

#form .success {
    display: none;
    position: absolute;
    width: 100%;
    color:#39596e;

     border: 1px solid #3c7f9f;

    background-color: #c2e8f4;

    text-align: center;
    padding: 20px 10px;
    z-index: 999;
    box-sizing: border-box;
    -moz-box-sizing: border-box; /*Firefox 1-3*/
    -webkit-box-sizing: border-box; /* Safari */
}

.success_wrapper {
    position: relative; 
}
Endone
  • 57
  • 6
  • try by changing Send to – Vivek Singh Apr 29 '16 at 11:28
  • What is the error you are getting – Web Artisan Apr 29 '16 at 11:29
  • when i click send, i will not processed to prosescomment.php – Endone Apr 29 '16 at 11:30
  • Please take some time to read both [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and [How can I prevent SQL-injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Your code is very outdated and very vulnerable to hacker attacks. – Oldskool Apr 29 '16 at 11:30

3 Answers3

2

It seems you have a Connection Class or so... however I'd suggest you use Prepared Statements & PDO...

Besides, your SQL might be wrong depending on whether you have a Primary Key (ID) or not.

Here is the route I'd suggest you go:

    <?php
    include "connection.php";

    $nama       = htmlspecialchars(trim($_POST['nama']));       //PROTECT AGAINST SQL INJECTION
    $email      = htmlspecialchars(trim($_POST['email']));      //PROTECT AGAINST SQL INJECTION
    $message    = htmlspecialchars(trim($_POST['message']));    //PROTECT AGAINST SQL INJECTION

    //NOTE: YOU DON'T HAVE THE VARIABLE $comment DEFINED: YOU MUST MEAN $message
    $query      = "INSERT  INTO comment (name, email, message) VALUES ('$nama', '$email', '$message')";

    /** I WOULD SUGGEST YOU USE PDO  & PREPARED STATEMENTS LIKE SO*/
    // $stmt       = $dbh->prepare("INSERT INTO comment (name, email, comment) VALUES (:name, :email, :message)");
    // $stmt->bindParam(':name', $nama);
    // $stmt->bindParam(':email', $email);
    // $stmt->bindParam(':message', $message);

    $result = mysql_query($query);
    // NOT if($query) BUT if($result) BECAUSE $query IS A STRING AND if($query) WILL ALWAYS RETURN TRUE... 
    if ($result) {
        header("location:index.html");
    }
    else{
        mysql_error();
    }
?>

I hope this helps a bit...

Poiz
  • 7,611
  • 2
  • 15
  • 17
  • I really hope OP follows your suggestion. In fact, it'd be the only thing I'd put in the answer. mysql_ has officially died and shouldn't actively be "promoted" in answers anymore IMHO. – Oldskool Apr 29 '16 at 11:51
  • Thanks Oldskool but honestly, you are completely right. PDO is actually easier to deal with than mysql_ . We should leave that to OP to decide for himself. That's why I left it inside the code as a comment... ;-) – Poiz Apr 29 '16 at 11:59
1

chage your html and prosescomment.php code with this codes and it will run

 <form action="prosescomment.php" method="POST"  id="form" >
              <div class="success_wrapper">
                <div class="success">Contact form submitted!<br>
                  <strong>We will be in touch soon.</strong> </div>
              </div>
              <fieldset>
                  <input type="text" name="nama" placeholder="Name:">
                  <br class="clear">
                  <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span>
                <label class="email">
                  <input type="text" name="email" placeholder="E-mail:">
                  <br class="clear">
                  <span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
                <label class="message">
                  <textarea type="text" name="message" placeholder="Message"></textarea>
                  <br class="clear">
                  <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
                <div class="clear"></div>
                <div class="btns"><input type="submit" name="submit" value="send" class="link1"/>
                  <div class="clear"></div>
                </div>
              </fieldset>
            </form>




<?php 
    include "connection.php";
if(isset($_POST['submit']))     // 
{
    $nama = $_POST['nama'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $query = "INSERT  INTO comment VALUES ('$nama', '$email', '$message')";
    $result = mysql_query($query);

    if ($result) {
        header("location:index.html");
    }
    else{
        mysql_error();
    }
}
 ?>
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
0

Please replace line of code <a data-type="submit" class="link1">Send</a> to <button class="link1" type="submit" >Send</button> and try your form data will post.

Manish Silawat
  • 900
  • 5
  • 7