M
M
Minningt2015-11-07 19:31:46
PHP
Minningt, 2015-11-07 19:31:46

How to fix add error? Field lighting?

Once again, hello everyone. In general, I figured out the captcha, it is checked if the input is incorrect, but !!!
1. When I enter characters incorrectly, the form is updated. How to fix?
2. When I enter everything correctly, how to add data to the database? At the moment, through ajax, it just writes emptiness (such as success)
3. How to highlight the field with a red frame if it is empty, and not write an alert? And you need to highlight what is empty

File check_capcha

session_start();
if ($_SESSION["code"] == $_POST["captcha"]) {
    if (isset($_POST["send"])) {
    $name     = $_POST['com_name'];
    $email    = $_POST['com_email']; 
   $query = 'INSERT INTO comments (name, email) VALUES (:name, :email)';
    $stmt = $pdo->prepare($query);
    $stmt->execute(array( ':name'=>$name, ':email'=>$email));    
  }
}   
else { 
    die("Wrong TEXT Entered");
}


js file

$('#send_com').click(function() {
  
    var name = $('#name').val();
    var email = $('#mail').val();
    var captcha = $("#captcha").val();

      if (name == '' || mail == '' || captcha == '')
        {
          alert("Fill All Fields");
          return false;
        }
        else
        { 
          var dataString = 'captcha=' + captcha;
        $.ajax({
        type: "POST",
        url: "check_captcha.php",
        data: dataString,
        success: function(html) {
        alert(html);
        }
        });
        }
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2015-11-07
@Immortal_pony

1. When I enter characters incorrectly, the form is updated. How to fix?

Write the code to update the captcha, of course.
At this point, you receive a response from the server:
success: function(html) {
    alert(html);
}

Rewrite this section of code in such a way that it not only outputs the server response, but also processes it.
"In the database" - where exactly? There is some kind of connection to the database, perhaps there are some tables there, tables most likely have rows and fields. And now you want to add some line or change some field. Tell us what changes you want to make and what obstacles stand in your way?
Instead of alert'a, add a class to the specified field. With the help of css to the field with the specified class, the crane frame.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question