Getting the value from MySQL to check radio buttons generates a notice
I'm trying to set the "checked" status of a radio button based on the
value from the MySQL database. The main purpose of the code is to be a
"edit user profile data" script. I managed to get all information from the
database and everything gets edited as it should if the user choses to but
I can't seem to make the radio buttons work. I get the following message:
Notice: Use of undefined constant Male - assumed 'Male' in
C:\xampp\htdocs\Signup\user_panel.php on line 57
I checked SO for this notice but I couldn't find anything related to radio
buttons AND the notice.
This is the code:
<form action="includes/user_panel.php" method="POST">
<table>
<tr>
<td><label for="email"> E-mail </label></td>
<td><input type="email" name="email" id="email"
value="<?php echo "{$fetch['email']}"; ?>"></td>
</tr>
<tr>
<td><label for="first_name"> First name </label></td>
<td><input type="text" name="first_name"
id="first_name" value="<?php echo
"{$fetch['first_name']}"; ?>"></td>
</tr>
<tr>
<td><label for="last_name"> Last name </label></td>
<td><input type="text" name="last_name"
id="last_name" value="<?php echo
"{$fetch['last_name']}"; ?>"></td>
</tr>
<tr>
<td><label for="birthday"> Birthday </label></td>
<td><input type="date" name="birthday"
id="birthday" value="<?php echo
"{$fetch['birthday']}"; ?>"></td>
</tr>
<tr>
<td><label for="sex"> Sex </label></td>
<?php
if ($fetch['birthday'] = Male)
{
echo "<td><input type='radio' name='sex'
value='male' id='sex' checked> Male <input
type='radio' name='sex' value='female'
id='sex'> Female </td>";
}
else
{
echo "<td><input type='radio' name='sex'
value='male' id='sex'> Male <input
type='radio' name='sex' value='female'
id='sex' checked> Female </td>";
}
?>
</tr>
</table>
</br>
<input type="submit" name="edit_user" value="Edit"
class="button_1">
<input type="hidden" name="edit_user_data">
</form>
Additional information:
$initial_email = $_SESSION['email'];
$username = $_SESSION['username'];
$query_user_panel="SELECT * FROM users WHERE email = '$initial_email' OR
username= '$username'";
$result_user_panel=mysql_query($query_user_panel) or die (mysql_error());
$fetch = mysql_fetch_assoc($result_user_panel)
Line 57 is the one with the "if".
Scroll down the code and you'll see where the sex should get checked. I
tried with a "if" but that generates me the notice that I wrote.
I know that MySQL is depreciated and I should use MySQLi. If you have the
time please check this question as well: Simplest MySQL to MySQLi
transition
Thank you very much and please let me know if I need to edit my post or
provide with additional data.
No comments:
Post a Comment