Jump to content

Notice: Undefined index: submit


jmevz

Recommended Posts

Hi There,

 

I'm a NEWBY PHP and am following this tutorial "http://youtu.be/U1jFhFM4l8o".

 

I've copied his code almost exactly but with my credentials as I have designed my database a little differently, but I don't see why his page loads fine yet for all of my $variable lines I get this error: "Notice: Undefined index: submit in C:\xampp\htdocs\indiemunity\register.php on line 7". I'm presuming I need to open the connection to the database on each page accessing it and close it at the end, which is why I have the include where the tutorial doesn't. I just don't get this? Am I declaring the variables incorrectly? Possibly due to different version of PHP?

 

I'm running XAMPP/PHPMyAdmin/SQL.

 

MY CODE BELOW

-------------------------------------------------------------------------------------------------------------------------------

<?php

include_once 'dbconnect.php';

 

echo "<h1>Register</h1>";

 

// Form Data

$submit = $_POST['submit'];

$useremail = $_POST['useremail'];

$username = $_POST['username'];

$userpassword = $_POST['userpassword'];

$userpasswordcheck = $_POST['userpasswordcheck'];

 

?>

 

<html>

 

<form action='register.php' method='POST'>

 

<table>

<tr>

<td>

Email:

</td>

<td>

<input type='text' name='useremail'>

</td>

</tr>

<tr>

<td>

Username:

</td>

<td>

<input type='text' name='username'>

</td>

</tr>

<tr>

<td>

Password:

</td>

<td>

<input type='password' name='userpassword'>

</td>

</tr>

<tr>

<td>

Repeat:

</td>

<td>

<input type='password' name='userpasswordcheck'>

</td>

</tr>

</table>

 

<p>

<input type='submit' name='submit' value='Register'>

 

</form>

 

</html>

-------------------------------------------------------------------------------------------------------------------------------

THE ERROR

-------------------------------------------------------------------------------------------------------------------------------

Notice: Undefined index: submit in C:\xampp\htdocs\indiemunity\register.php on line 7

 

Notice: Undefined index: useremail in C:\xampp\htdocs\indiemunity\register.php on line 8

 

Notice: Undefined index: username in C:\xampp\htdocs\indiemunity\register.php on line 9

 

Notice: Undefined index: userpassword in C:\xampp\htdocs\indiemunity\register.php on line 10

 

Notice: Undefined index: userpasswordcheck in C:\xampp\htdocs\indiemunity\register.php on line 11

-------------------------------------------------------------------------------------------------------------------------------

 

Hope you can help. I'm sure it's something simple.

 

Thanks in advance,

Jeff

jnst17@tpg.com.au - Interested in helping me further as well? Email me :)

Link to comment
Share on other sites

Undefined index means u have variables that are not set. there empty.

u are calling the vars at the top of the page before they are entered into a form and submitted.

so if u use logic u have to call them AFTER submission

 

is this 1 page or more? typicaly a form is the 1st page and on submission the data gets sent to anothe processing page, allthough u can do it on 1 page.

 

to get around the undifine index error u need the isset function

 

<?php
if (isset($_GET['email'])){
code that contains the variable u want.
}
?>

Link to comment
Share on other sites

hi...look ur line "<form action='register.php' method='POST'>".......in this u notice action=register.php  dis means that all the data inserted by the user and then contaned in the variables is forwarded to register.php and you are trying to receive on the same page...if you want to eliminate these error..u just cut  section mentioned below from the code and paste it at the begging of register.php

 

// Form Data

$submit = $_POST['submit'];

$useremail = $_POST['useremail'];

$username = $_POST['username'];

$userpassword = $_POST['userpassword'];

$userpasswordcheck = $_POST['userpasswordcheck'];

Link to comment
Share on other sites

@hyster:

 

There is the only 1 register page, I'd rather not create another page for processing the form, would rather do it all in one.

 

So, I presume I have to use the; if (isset($_GET['email'])) for every field of the form. So, this reads:

 

If there is data in the form, set email to value and then post?

 

Regards,

Jeff

 

 

Link to comment
Share on other sites

@hyster:

 

No, I think you were right anyway, so I've done this:

---------------------------------------------------------------------------------------------------------------------

// Get form data and assign to Variable.

 

if (isset($_GET['submit'])){

$submit = $_POST['submit'];

}

if (isset($_GET['useremail'])){

$useremail = $_POST['useremail'];

}

if (isset($_GET['username'])){

$username = $_POST['username'];

}

if (isset($_GET['userpassword'])){

$userpassword = $_POST['userpassword'];

}

if (isset($_GET['userpasswordcheck'])){

$userpasswordcheck = $_POST['userpasswordcheck'];

}

---------------------------------------------------------------------------------------------------------------------

Now, am I correct in saying that the above is, in plain English: If form field contains value, get that value and assign to variable. Now that that variable is assigned, I can then use the INSERT INTO function to insert those variables into my database?

 

I'm a bit worried about the passwordcheck option though and how to render that as their is no actual field in my database for that.

 

Regards,

Jeff

 

Thanks Heaps!

Link to comment
Share on other sites

i forgot to change the _get to _post

 

hope that makes sense

<?php
if (isset($_post['submit'])){
$submit = $_POST['submit'];

if (isset($_post['useremail'])){
$useremail = $_POST['useremail'];

if (isset($_post['username'])){
$username = $_POST['username'];

if (isset($_post['userpassword'])){
$userpassword = $_POST['userpassword'];

if (isset($_post['userpasswordcheck'])){
$userpasswordcheck = $_POST['userpasswordcheck'];

////////////////
sql code  and other code that contains the variables goes here
////////////////

}
}
}
}
}

?>

Link to comment
Share on other sites

will look something like this

<?php

if (isset($submit])){
$submit = $_POST['submit'];

    if (isset($useremail])){
    $useremail = $useremail];

        if (isset($username])){
        $username = $_POST['username'];

            if (isset($userpassword])){
            $userpassword = $_POST['userpassword'];

                if (isset($userpasswordcheck)){
                $userpasswordcheck = $_POST['userpasswordcheck'];

                // check passwords match
                      if ($userpassword = $userpasswordchech){

                              $sql="INSERT INTO $tbl_name (submit, useremail, username, userpassword) values 
                              ('$submit', '$useremail', '$username', '$userpassword')";
                              $result=mysql_query($sql);
                              
                              // check the sql statment worked ok
                                      if($result){
                                      echo "Update Successful";

                                      }
                                      else {
                                      echo "ERROR"; 
                                      }

                              }
                              }else{

                      echo "your password do not match"
                  }
            }
        }
    }
}

?>

Link to comment
Share on other sites

@hyster:

 

Hey, thanks for the code example, you're a legend. I ended up creating insert.php and adding my INSERT SQL to that, which work, but without the password check. I feel creating the second insert file pointless really, because when am I ever going to use that same insert statement somewhere else? Pointless...

 

I will give your method below a shot. Thanks heaps, will let you know how I go :)

 

Regards,

Jeff

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.