php form submit not working. Can you tell me what's wrong with this code?

by man5
3 replies
Everytime I submit a form, I get nothing. It doesn't insert into database on submit and it doesn't give me any errors. I can't figure out what's wrong with it.

if(isset($_POST['submit'])) {    
                        $email = trim($_POST['email']);
                        if(empty($_POST['email'])) {
                            $error = 'Please enter your email address.';
                        } else {
                            $newEmail = $email;
                            $date      = date('Y-m-d H:i:s');
                            $insert = $db->prepare("INSERT INTO email_list(email, date) VALUES(:email, :date)");
                            $insert->bindParam(':email', $newEmail);
                            $insert->bindParam(':date', $date);
                            $result = $insert->execute();
                            if($result == false) {
                                $error = 'There seems to be a problem. Please try again.';
                            } else {
                                $success = 'success.';
                    <div id="error"><?php echo $error; ?></div>
                    <div id="success"><?php echo $success; ?></div>
                    <form action="" type="post" enctype="multipart/form-data">
                        <input type="text" name="email" placeholder="Enter email address"/>
                        <input type="submit" name="submit" value="Notify Me"/>
#form #php #submit #working
  • Profile picture of the author man5
    I found the issue. type="post" has to be changed to method="post".
    {{ DiscussionBoard.errors[9935229].message }}
  • Profile picture of the author javrsmith
    If you use Firebug on FireFox, it may have caught that error for you, and displayed it on the execution log.
    {{ DiscussionBoard.errors[9941234].message }}
  • Profile picture of the author gripawa
    ur missing some code sir
    {{ DiscussionBoard.errors[9949516].message }}

Trending Topics