Hi there, I am fairly new to php and have been following some basic tutorials… The current tutorial I am following is actually about creating a form with a single name input text field and 4 radio buttons. The form uses an external php document to process and post back the users name and the radio button option they selected.
The form did work fine running it in localhost on WAMP, but then I decided to attempt to change the $name variable in PHP and Name text input field in HTML to the following $firstname - Firstname…then I added an additional HTML text field named Second Name and a PHP variable to match = $secondname…
I get the following error in an orange table:
Notice: Undefined index: lastname in C:\wamp\www\Dynamic_Web_Design_with~_PHP_and_MySQL_Working Files\Chapter03\0306_Using_RadioButtons1.php on line 16
function =
{main}( )
location =
…\0306_Using_RadioButtons1.php:0
I wanted to change/update the scripts to output the users surname also you see…but after trying several ideas that failed due to my lack of knowledge, I found something similar that someone had done in another online text tutorial but for some reason I cant seem to achieve this basic goal…
I have also tried removing browser cache and history in-case it was using previous data;
I will paste the code below and would appreciate any help with this:
HTML File:
[code]
[color=black][color=red]
Using the RadioButtonsUsing the RadioButtons
<!--First Name Field Starts-->
<p>
First Name:<br />
<input type="text" name="firstname" size="30">
</p>
<!--First Name Field Ends-->
<!--Last Name Field Starts-->
<p>
Last Name:<br />
<input type="text" name="laststname" size="30">
</p>
<!--Last Name Field Ends-->
<!--Employee Type radio button selection starts here-->
<br>
<p>
Employee Type:
<br>
<br>
<input type="radio" name="etype" value="Fulltime" checked="checked"> Fulltime
<p>
<input type="radio" name="etype" value="Parttime"> Partime
</p>
<p>
<input type="radio" name="etype" value="Unemployed"> Unemployed
</p>
<!--Employee Type radio button selection ends here-->
<!--The form submit button starts here-->
<p>
<input type="submit" value="Submit Information">
</p>
<!--The form submit button ends here-->
[/code]
PHP File:
[code]
Using RadioButtonsUsing RadioButtons
[php]<?php
$firstname = $_POST['firstname'];
$lastname = $_POST ['lastname'];
$etype = $_POST['etype'];
$fullname = "$firstname $lastname";
//The html form field names are applied/defined to php variables here.
// It is ld the users entries which will be shown in place of the variables within the html below.
print "<p>You are <span class='textblue'>$fullname</span> and ";
print "your employment type is: ";
print "<span class='textblue'>$etype</span></p>";
?>[/php]
[/code];D
CSS-External file:
[code]html {margin:0; padding:0;}
body {
font-family: Arial, Helvetica, sans-serif;
color: black;
background-color: #F0E68C;
}
p {
font-size: 16px;
}
input {
font-size: 16px;
}
select {
font-size: 16px;
}
textarea {
font-size: 16px;
font-family: Arial, Helvetica, sans-serif;
}
.textblue {
color: blue;
}
.textdisabled {
background-color: lightgray;
}
[/code]