0

please help why everytime when I run it it has this undefined error

       (     Notice: Undefined index: u_role in C:\xampp\htdocs\mysite\membership.php on line 136

/> Member Notice: Undefined index: u_role in C:\xampp\htdocs\mysite\membership.php on line 137
/> Administrator)

        <td>User Role:*</td>
        <td><input type="radio" name="u_role"  value="Member" <?php if($_POST['u_role']=="Member"){echo"checked='checked'";}?> /> Member
         <input type="radio" name="u_role"  value="Administrator" <?php if($_POST['u_role']=="Administrator"){echo"checked='checked'";}?> /> Administrator </td>
                </tr> 

                 <tr>

               /*  and also the gender */
                 <tr>
        <td>Gender:*</td>
        <td><select name="gender">
            <option value=""></option>
            <option value="Male"> <?php if($_POST['gender']=="Male"){echo "selected='selected'";}?>Male</option>
            <option value="Female"> <?php if($_POST['gender']=="Female"){echo "selected='selected'";}?>Female</option>
        </select> </td>
        </tr>
3
Contributors
5
Replies
37
Views
3 Years
Discussion Span
Last Post by Ann Krizette
0

please help why everytime when I run it it has this undefined error

@Ann Krizette

You need to add isset() function to see whether u_role to see whether it exists.

For example like this:

if (isset($_POST["u_role"]) && !empty($_POST["u_role"])) {
echo "checked";    
}else{  
echo "not checked";
}
0

AS LM says. However, as you're using a radiobutton, u_role should always be set, so you need to set one of them to 'checked' as default. So LM's code will probably set the last radiobutton regardless of which one was set on form submit because it doesn't check for the value.

<?php
$memCheck = (!isset($_POST["u_role"]) || $_POST["u_role"] == 'Member')) ? "  checked = 'checked'" : "";
$admCheck = (isset($_POST["u_role"]) && $_POST["u_role"] == 'Administrator')) ? "  checked = 'checked'" : "";
?>


 <td><input type="radio" name="u_role"  value="Member"<?php echo memCheck;?> /> Member
         <input type="radio" name="u_role"  value="Administrator"<?php echo admCheck;?> /> Administrator </td>
0

thank you LM but its not working :(

Diafol can you help me., theres a syntax error in the code you've given..tnx

0
$memCheck = (!isset($_POST["u_role"]) || $_POST["u_role"] == 'Member') ? "  checked = 'checked'" : "";
$admCheck = (isset($_POST["u_role"]) && $_POST["u_role"] == 'Administrator') ? "  checked = 'checked'" : "";

Substitute that bit - I put in too many parentheses. That's was comes from coding off the top of your head. :)

Also...

<td>
    <input type="radio" name="u_role"  value="Member"<?php echo $memCheck;?> /> Member
    <input type="radio" name="u_role"  value="Administrator"<?php echo $admCheck;?> /> Administrator
</td>

Notice the $ for the vars - I forgot those too. :(

Edited by diafol

0

Thank you guys for helping me code complete,, thank you DIAFOL...no error at all and working :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.