0

I get this error for every $_POST item, except $fname, $mname and $lname. I don't understand why though. I have searched for a solution, and the suggestion of isset is most common, but I have tried it in several different forms and it is still not working for me.

Notice: Undefined index: postcode in C:\xampp\htdocs\php\signin.php on line 13

Notice: Undefined index: homephone in C:\xampp\htdocs\php\signin.php on line 15

Notice: Undefined index: mobphone in C:\xampp\htdocs\php\signin.php on line 16

signin.php

<?php

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

    $fname=$_POST['firstname'];
    $mname=$_POST['middlename']; 
    $lname=$_POST['lastname'];
    $dob=$_POST['dateofbirth'];
    $address=$_POST['address'];
    $city=$_POST['city'];
    $state=$_POST['state'];
    $country=$_POST['country'];
    $postcode=$_POST['postcode'];
    $email=$_POST['email'];
    $homephone=$_POST['homephone'];
    $mobphone=$_POST['mobphone'];
    $preferred=$_POST['preferred'];

    include_once("includes/link.php");

    $sql=("INSERT INTO `member` VALUES ('$fname', '$mname', '$lname', '$dob', '$address', '$city', '$state', '$country', '$postcode', '$email', '$homephone', '$mobphone', 'preferred')");

    mysqli_query($link, $sql);

    mysqli_close($link);
    }
?>

link.php

<?php

    $hostname = "localhost";
    $user = "root";
    $password = "********";
    $link = mysqli_connect($hostname, $user , $password);

    if (!$link){
    echo "server is being lame";
    exit;
    };
    mysqli_select_db($link, "cp2cwonrlvDB3");
    if (!mysqli_select_db($link, "cp2cwonrlvDB3")){
    echo "Could not connect brudda";
    };

?>

Form html:

<html>
<head>
<title>Example form</title>
<style type="text/css">

label
{
width: 100px;
float: left;
text-align: right;
margin-right: 0.5em;
display: block
}

.reset {
margin-left:50px;
}

h3 {
margin-left:15px;
}

</style>
<script>
<?php
    include 'includes/connection.php'
?>
</script>
</head>

<body>

<div class="container">
    <h2>Sign up to CWON</h2>
    <form method="POST" action="signin.php" novalidate>

        <label for="fisrtname">First Name:</label>
        <input type="text" name="firstname" required placeholder="Enter your first name" maxlength="25"><br />

        <label for="middlename">Middle Name:</label>
        <input type="text" name="middlename" placeholder="Enter your middle name"  maxlength="25"><br />

        <label for="lastname">Last Name:</label> 
        <input type="text" name="lastname" required placeholder="Enter your last name"  maxlength="25"><br />

        <label for="dateofbirth">Date of Birth:</label> 
        <input type="date" name="dateofbirth" required maxlength="25"><br />

        <label for="address">Address:</label> 
        <input type="text" name="address" required maxlength="100" placeholder="Enter your home address"><br />

        <label for="city">City:</label> 
        <input type="text" name="city" required maxlength="100" placeholder="Enter your city"><br />

        <label for="state">State:</label> 
        <select name="state">
            <option value="NSW">NSW</option>
            <option value="QLD">QLD</option>
            <option value="VIC">VIC</option>
            <option value="SA">SA</option>
            <option value="WA">WA</option>
            <option value="NT">NT</option>
            <option value="TAS">TAS</option>
        </select> <br />

        <label for="country">Country:</label> 
        <input type="text" name="country" required maxlength="100" placeholder="Enter your country"><br />

        <h3>Preferred contact:</h3>
        <label for="preferred">Home Phone:</label>
        <input type="radio" name="preferred" value="Home Phone"><br /><br />

        <label for="preferred">Mobile Phone:</label>
        <input type="radio" name="preferred" value="Mobile Phone"><br /><br />

        <label for="preferred">Email:</label>
        <input type="radio" name="preferred" value="Email"><br /><br />

        <label for="homenumber">Home Number:</label>
        <input type="text" name="homenumber" placeholder="Enter your home number"><br />

        <label for="mobnumber">Mobile Number:</label>
        <input type="text" name="mobnumber" placeholder="Enter your mobile number"><br />

        <label for="email">Email Address:</label> 
        <input type="email" name="email" required maxlength="100" placeholder="Enter your email address"><br />

        <label for="postcode">Postcode:</label>
        <input type="number" name="postcode" required min="1000" max="9999" placeholder="4-digit"><br />

        <label for="occupation">Occupation:</label> 
        <input type="text" name="occupation" maxlength="50" placeholder="Enter your occupation"><br />

        <label for="hobbies">Hobbies:</label> 
        <input type="text" name="hobbies" maxlength="200" placeholder="separate with commas"><br />

        <label for="interest">Interests:</label> 
        <select name="interest">
            <option value="Fund Raisers">Fund Raisers</option>
            <option value="Domestic Volunteering">Domestic Volunteering</option>
            <option value="Foreign Volunteering">Foreign Volunteering</option>
            <option value="All of the above">All of the above</option>
        </select> <br /><br />

        <label for="terms">Terms and Conditions</label> 
        <input type="checkbox" name="terms"><br /><br /><br />

        <label for="newsletter">Sign up for the CWON newsletter</label> 
        <input type="checkbox" name="newsletter"><br /><br /><br /><br />

        <input type="reset" name="reset" value="Reset" class="reset" onclick="set_focus()" />
        <input type="submit" name="submit" value="Submit" class="submit">

    </form>
</div>
1
  • 1
    check for every POST field isset($_POST['field_name']) Commented May 2, 2014 at 6:08

4 Answers 4

4

See you have $ inside of the $_POST array. Remove them all.

 $dob=$_POST['$dateofbirth'];
              ^------------------ That (Remove them all)

EDIT :

You need to change the name of your postcode as it reflects the mobphone.

 <label for="postcode">Postcode:</label>
 <input type="number" name="postcode" required min="1000" max="9999" placeholder="4-digit"><br />

Now change them as...

$homephone=$_POST['homenumber']; //<--- Should be homenumber.`
$mobphone =$_POST['mobnumber'];
$postcode =$_POST['postcode'];
Sign up to request clarification or add additional context in comments.

5 Comments

So obvious and yet so hidden. :3
I have removed them, and now I am left only with the three errors you see in the edited question above.
Fox , please post the HTML code as asked by @YUNOWORK on your question too.
@Fox, Hope you did the changes , but always make use of an isset construct before checking the request variables...
@Fox, Filter your variables with mysqli_escape_string to avoid SQLInjection.
2

You need to check and make sure there are values before you try to access the parameters. That will make sure that they are set before you try and use them. This can be done using the isset() function. Example:

// check values exist before using them
if(isset($_POST['$dateofbirth'])){
    $dob=$_POST['$dateofbirth'];
}

Also, your SQL is vulnerable to injection. You really should sanitize your parameters before you use them in a query. MySQLi Parameterized Queries or PDO Queries would be recommended for this.

Notice how the final error doesn't include the $, so removing that won't full solve the issue.

2 Comments

You are right about sanitizing, but I am merely playing around with inserting to a dummy website to learn. As for checking the values, I'm not entirely sure how to do this with my skill level. I will read into it.
Edited to suggest approach for checking values ;)
1

Change:

$dob=$_POST['$dateofbirth'];

To:

$dob=$_POST['dateofbirth'];

Same for all.

2 Comments

you have forgot to ommit '$' from field name
Thanks, despite the error, you answered swiftly. Now I am only left with three similar errors.
0

you don't have inputs with name 'homephone' and 'mobphone', just 'homenumber' and 'mobnumber'

$homephone=$_POST['homenumber'];
$mobphone=$_POST['mobnumber'];

Comments

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.