2

I have a form which can be seen below:

<form id="myForm" action="register.php" method="POST">
    <input type="text" name="email" id="email" onfocus="fieldSwap('inputhover.png')" 
        onblur="fieldSwap('inputnorm.png')"><br/>
    <input type="image" src="submitnorm.png" name="submit" id="submit" 
        alt="submit button" onMouseOver="buttonSwap('submithover.png')" 
        onMouseOut="buttonSwap('submitnorm.png')" 
        onMouseDown="buttonSwap('submitclick.png')" 
        onMouseUp="buttonSwap('submitnorm.png')"/>
</form>

It calls this script:

<?php
    require_once 'db.php';

    $email = $_POST['email'];
    echo $email;
    echo "Register form";
    $sql->$db->prepare("INSERT INTO emails SET email = :email");
    $sql -> bindValue(':email', $email, PDO::PARAM_STR);
    $sql -> execute();

    // Redirect back to homepage
    header('Location: index.php');
    exit();
?>

I am getting this error:

Notice: Undefined index: email in C:\wamp\www\Holding page\register.php on line 3

What am I doing wrong? I understand that no index called email exists in the POST array but I am unsure why this is the case. Thanks!

5
  • depending on your doctype you should write post small. Commented May 24, 2013 at 21:12
  • 2
    Use print_r($_POST); to check what are the values stored in $_POST. Commented May 24, 2013 at 21:13
  • 1
    Are you sure that input type image does what you want? have you tried to submit it via input type submit? Commented May 24, 2013 at 21:14
  • @lorey changing the input type to submit did the trick. Thanks, I'll accept as answer when you post Commented May 24, 2013 at 21:18
  • But he can enter it in the browser if he wants? Commented May 24, 2013 at 21:39

2 Answers 2

2

Try submitting your form via

<input type="submit" value="send">

and see if that works with `print_r().

Sadly, I don't know why <input type="image"> is not working for you. Try checking the doctype (must be HTML5) and your browser (too old?).

Sign up to request clarification or add additional context in comments.

Comments

0

you forget to add value attribute in email as well as if input type=image not working for submit button then you may try type=submit

<form id="myForm" action="register.php" method="POST">
<input type="text" name="email" id="email" value="" onfocus="fieldSwap('inputhover.png')" onblur="fieldSwap('inputnorm.png')"><br/>
<input type="submit" src="submitnorm.png" name="submit" id="submit" alt="submit button" onMouseOver="buttonSwap('submithover.png')" onMouseOut="buttonSwap('submitnorm.png')" onMouseDown="buttonSwap('submitclick.png')" onMouseUp="buttonSwap('submitnorm.png')"/>
</form>

1 Comment

<input type="image"> is part of HTML5 w3.org/TR/html-markup/input.image.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.