help i have bit knowledge in html,css but im kinda new to php forms,database,etc stuffs
my php is working well, when user click submit all forms goes to carlist.txt
but i want it output it through webpage html instead of .txt so i can view it online how i can able to do that?
and i dont want the users sees their submisions... only me can view it
html :
<html>
<form action"awesome.php" method=get>
First name: <input type="text" name="firstname"><br>
blah.. blahh.
<select name="cars">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<input type="submit" value="Submit">
</form>
etc. etc. blah blah
</html>
awesome.php:
<?php
header("Location: thanksforsubmiting.html");
$handle = fopen("carslist.txt", "a");
foreach($_GET as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "
");
}
fwrite($handle, "
");
fclose($handle);
exit;
?>
thanksforsubmitting.html:
<html>
<title>thank you</title>
<h1> <font color=red>
thank you for submission </h1></font>
</html>
please be gentle to me im kinda newbie :)) TIA
at awesome.php write following code
if(isset($_GET['submit'])){
$firstName = $_GET['firstname'];
$car = $_GET['cars'];
echo $firstname;
echo $car;
}
<?php
foreach($_GET as $variable => $value) {
echo $value."<br />";
}
?>
If you want view it online create another page with something like this
$file = file_get_contents('carlist.txt');
$rows = explode("
", $file);
foreach($rows as $row) {
print_r($row);
}
ok here is an example code you want. i'm using just 2 files form.php and form1.php. Form.php contains:
<?php
if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
header("Location:form1.php");
}
?>
<form name="test" action="" method="post">
<label for="fname">First Name:</label>
<input type="text" name="fname"/>
<label for="lname">Last Name:</label>
<input type="text" name="lname"/>
<input type="submit" name="submit" />
</form>
and form1.php contains following statement:
<?php
echo "Form Submitted!";
?>
On submition form will stay on the same page since action is null in form. In the if statement it will be redirected!