Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Undefined Index

<?php 
if(isset($_GET['r'])){
    $fullname= $_POST['fullname'];
    $username= $_POST['username'];
    $email= $_POST['email'];
    $message= $_POST['message'];
    $status= "pending";

    require ('inc/db_connect.php');
    $order ="INSERT INTO message (username, fullname, email, message, status)
             VALUES('$username','$fullname','$email','$message','$status')";
    $result=mysqli_query($con,$order);
    if($result){
        $feedback= "Your message had been sent, we will soon reply to your query.";
    } else {
        $feedback= "Something went wrong, please try again later.";
    }
    //mysqli_close($con);

}
    if(isset($_COOKIE['id'])){
        $id= $_COOKIE['id'];
        require ('inc/db_connect.php');

        $order= "SELECT name,username,email FROM persons WHERE id='$id'";
        $result= mysqli_query($con,$order);
        $row= mysqli_fetch_array($result);
        $full_name=$row['name'];
        $user_name=$row['username'];
        $email_=$row['email'];

        mysqli_close($con);
        if(isset($feedback)){
            echo $feedback;
        }
        ?>
        <form method="POST" action="support.php?r=send">
            <input type="text" name="fullname" id="fullname" value="<?php echo htmlspecialchars($full_name); ?>" >
            <input type="text" name="username" id="username" value="<?php echo htmlspecialchars($user_name); ?>" >
            <input type="email" name="email" id="email" value="<?php echo htmlspecialchars($email_); ?>" >
            <textarea name="message" id="message"></textarea>
            <input type="submit" value="Send">
        </form>

        <?php  }else { 
            if(isset($feedback)){
            echo $feedback;
        } ?>

        <form method="POST" action="support.php?r=send">
            <input type="text" name="fullname" id="fullname">
            <input type="text" name="username" id="username">
            <input type="email" name="email" id="email">
            <textarea name="message" id="message"></textarea>
            <input type="submit" value="Send">
        </form>
    <?php }
?>

Why I am getting undefined index fullname, username, email error?

2 Answers

Try doing a var_dump($row), see if its returning any values.

The code was right, I don't know why it was showing errors, I tried and now it worked.