Jump to content

beginner errors issue for me


divinedesigns1

Recommended Posts

ok so i started off with a radio button well two radio buttons to be exact, and i keep on having this issue but i check to make sure i didnt misspelled anything and so on but i still getting this same problem, also when i click on the one of the radio buttons it works

 

heres the error

Notice: Undefined index: position in D:\wamp\www\Website\admin\testing.php on line 65

and this is the code for the above issue

if(isset($_POST['submit'])){
                        // define the variables
                        $Title = $_POST['title'];
                        $Detail = $_POST['description'];
                        $Position = $_POST['position'];
                        echo $Position;
                        // define the error too
                        $errors = array();
                        // now sanitized please
                        $Title = strip_tags(trim($Title));
                        $Detail = strip_tags(trim($Detail));
                        $Title = preg_match("/^[a-zA-Z0-9]*$/", $Title);
                        $Detail = preg_match("/^[a-zA-Z0-9]*$/", $Detail);
                        // now lets see if its empty
                        if(empty($Title) && empty($Detail) && empty($Position)){
                            $errors[] = 'All Fields Are Required';
                        }
                        foreach($errors as $error){
                            echo $error;
                        }
                    }
                     echo '<form action="testing.php" method="POST" enctype="multipart/form-data">
                             <input type="text" name="title" value="">
                             <textarea name="description" col="8" row="24"></textarea>
                             <input type="radio" name="position" value="a">Main Position
                             <input type="radio" name="position" value="b">Second Position
                             <input type="submit" name="submit" value="Save">
                             </form>';

any tip or advice on this one?

Link to comment
Share on other sites

If none of the radio buttons is selected, and therefore it is not set, by referencing of 'position' index which is not set and therefore does not exist will throw a error.

 

Check if set using isset(), before referencing.

ok thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...