Issue
Notice: Undefined index: gender in C:\xampp\htdocs\simv1\register.php on line 409
This my code so far :
<input type="radio" name="gender" value="Male">Male<br>
<input type="radio" name="gender" value="Female">Female
<?php if(isset($_POST['submit'])) {
$a = $_POST['gender'];
mysql_query("INSERT INTO register SET gender='$a');
}
?>
I've put if(isset())
on my PHP code but it not working.
I've read on Google before, I still confused. Can someone explain the problem with the solution?
Solution
This is one way to go. Also please do not use mysql as it is deprecated. Try using mysqli, or even PDO (I like PDO better).
Also, your SQL query is looking odd, so I have updated them as well.
<?php
if(isset($_POST['gender'])) {
$a = $_POST['gender'];
mysql_query("INSERT INTO register (gender) VALUES ('".$a."'"); //for insert
mysql_query("UPDATE register SET gender = '".$a."'"); // for update & don't forget to add the WHERE clause to avoid updating every record
} else {
$a = '';
}
?>
Answered By - Alex Szabo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.