Im trying to re-populate a field in my form but when I go inside my website it show some weird warning or code inside this field which is:
Notice: Undefined index: firstname in /home/int322_133a31/apache/htdocs/lab5/forms-part3.php on line 24
This is some part of my code for the form
<body>
<form method="post" action="forms-part3.php">
<table>
<tr>
<th colspan="2">FSOSS Registration</th>
</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<td class="right text">Title:</td>
<td><input type="radio" name="sex" value="male">Mr.</td></tr>
<tr><td></td><td><input type="radio" name="sex" value="female">Mrs.</td></tr>
<tr><td></td><td><input type="radio" name="sex" value="female">Ms.</td>
</tr>
<tr>
<td class="right text">First Name:</td>
<td><input type="text" name="firstname" size="28" value="<?php echo $_POST['firstname'];?>"></td>
</tr>
</table>
And this is for getting what the user input
<?php
if ($_POST){
$sex=$_POST['sex'];
$firstName=$_POST['firstname'];
$lastName=$_POST['lastname'];
$organization=$_POST['organization'];
$email=$_POST['emailaddress'];
$phone=$_POST['phonenumber'];
$selection=$_POST['selection'];
?>
The warning might be showing up first time when you visit the page since the $_POST
is not set yet.
Change,
<td><input type="text" name="firstname" size="28" value="<?php echo $_POST['firstname'];?>"></td>
To,
<td><input type="text" name="firstname" size="28" value="<?php if(isset($_POST['firstname'])){echo $_POST['firstname'];} ?>"></td>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments