Jump to content

PHP coding errors :(


jamesyrawr

Recommended Posts

i seem to get the following errors:

Notice: Undefined index: submit in C:\wamp\www\registration\register.php on line 12

 

Notice: Undefined index: fullname in C:\wamp\www\registration\register.php on line 14

 

Notice: Undefined index: username in C:\wamp\www\registration\register.php on line 15

 

Notice: Undefined index: password in C:\wamp\www\registration\register.php on line 16

 

Notice: Undefined index: repeat_password in C:\wamp\www\registration\register.php on line 17

 

its only in the php section that i am getting them

 

<?php


//Form Data
echo "<h1>Registration</h1>";


$submit = $_POST['submit'];

$fullname = $_POST['fullname'];
$username = $_POST['username'];
$password = $_POST['password'];
$repeat_password = $_POST['repeat_password'];


if ($submit)
{
   
}
?>


<html>
<form action='register.php' method='POST'>
<table>
    <tr>
        <td>
        Choose a Username:
        </td>
        
        <td>
        <input type='text' name="username">
        </td>
    </tr>
    <tr>
        <td>
        Password:
        </td>
        <td><input type='password' name="password">
        </td>
    </tr>
    <tr>    
        <td>
        Repeat Your Password:
        </td>
        <td><input type='password' name="repeat_password">
        </td>
    </tr>
    <tr>
        <td>
        Your Full Name:
        </td>
        <td><input type='text' name="name">
        </td>
    </tr>
        </table>
        <p><input type='submit' name='submit'></p>

</form>

</html>


Link to comment
Share on other sites

thanks for your reply but i'm still getting the same errors :(

below is the altered code

 

Notice: Undefined index: submit in C:\wamp\www\registration\register.php on line 12

 

Notice: Undefined index: fullname in C:\wamp\www\registration\register.php on line 14

 

Notice: Undefined index: username in C:\wamp\www\registration\register.php on line 15

 

Notice: Undefined index: password in C:\wamp\www\registration\register.php on line 16

 

Notice: Undefined index: repeat_password in C:\wamp\www\registration\register.php on line 17

 

<?php//Form Data
echo "<h1>Registration</h1>";


$submit = $_POST['submit'];

$fullname = $_POST['fullname'];
$username = $_POST['username'];
$password = $_POST['password'];
$repeat_password = $_POST['repeat_password'];


if (isset($_POST['submit']))
{
}
?>

Link to comment
Share on other sites

2 options

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

$fullname = $_POST['fullname'];
$username = $_POST['username'];
$password = $_POST['password'];
$repeat_password = $_POST['repeat_password'];
}

//OR

//Looks complex but I will explain
$fullname = isset($_POST['fullname']) ? $_POST['fullname'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
//Same for the rest



//Now that is short hand if statements 
// Basically ? is IF the condition is TRUE then : is the Else
// so 
$username = isset($_POST['username']) ? $_POST['username'] : '';
//is the same as 
if(isset($_POST['username']){
$username = $_POST['username'];
}else{
$username = '';
}

Link to comment
Share on other sites

thanks for the reply :)

i have a new error now

 

i tried the second version you made and it still has errors in :(

<?php
echo "<h1>Registration</h1>";


if(isset($_POST['submit'])

$fullname = isset($_POST['fullname']) ? $_POST['fullname'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$repeat_password = isset($_POST['repeat_password']) ? $_POST['repeat_password'] : '';




if (isset($_POST['submit']))
{
}
?>

ihave attached a picture to show what my piece of software is saying

Thanks

James

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Take a look:

 

if(isset($_POST['submit'])

 

No parenthesis...

 

You also don't need this:

 

if (isset($_POST['submit']))
{
}

 

Because you're doing nothing there. Above you have the checks for the variables. Preferably, I'd re-think how you're going about it.

 

Use the first option.

 

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

$fullname = $_POST['fullname'];
$username = $_POST['username'];
$password = $_POST['password'];
$repeat_password = $_POST['repeat_password'];

// Do stuff with form data, validate. Then register.
}

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.