Reputation: 56
im new to php, i just want to echo firstname can anyone please help me !
When i click on the submit button it redirects to action.php and then i want to echo my firstname from the form from previous page.
Here is my code :
<?php
echo "Great! Thanks" . $s1 . " for responding to our survey" ;
?>
<head>
<title>Idiot Box Survey</title>
<meta charset="utf-8">
</head>
<body>
<form action="action.php" method="post">
<label>Firstname : </label>
<input type="text" name="fname"><br><br>
<label>Lastname : </label>
<input type="text" name="lname"><br><br>
<label>Year of birth : </label>
<input type="date" name="ybirth"><br><br>
<label>Year at School : </label>
<input type="date" name="yschool"><br><br>
<label>When will You Wake up : </label>
<input type="time" name="wake"><br><br>
<label>How much time you spend on studying : </label>
<input type="time" name="study"><br><br>
<label>How much time you spend on Video games : </label>
<input type="time" name="vgames"><br><br>
<label>How much time you spend on tv : </label>
<input type="time" name="tv"><br><br>
<label>How much time you spend with family : </label>
<input type="time" name="family"><br><br>
<label>How much time you spend with friends : </label>
<input type="time" name="friends"><br><br>
<label>When will You Sleep : </label>
<input type="number" name="sleep"><br><br>
<button type="submit" name="submit"> Submit Form </button>
</form>
</body>
Upvotes: 0
Views: 64
Reputation:
Since my edits are apparently not accepted in other answers. Instead of calling a non existing php variable in $s1, On your action.php page write this.
if($_POST["submit"]){
$fname = $_POST["fname"];
echo "Great! Thanks" . $fname . " for responding to our survey" ;
}
This allows your form to pass the submitted data to the desired script. When you hit the submit button, you'll see the value that you put into the fname input field.
Upvotes: 0
Reputation: 213
<?php echo $_POST['fname']?>
use the name attribute of the input to print the other fields
<?php echo $_POST['lname']?> //for the last name and soo ..
Upvotes: 0
Reputation: 731
action.php appears to be missing from your question, but either way, your first name will be in $_POST['fname']
Upvotes: 1