Codes in main.html:
-----------------------------------------------------------
<html>
<body>
<form action="process.php" method="post">
Your name: <input type="text" name="name" /><br/>
Your address: <input type="text" name="address" /><br/>
Your tel number: <input type="text" name="telNum" /><br/>
Your email: <input type="text" name="email" /><br/>
<input type="submit" />
</form>
</body>
</html>
-----------------------------------------------------------
Codes in process.php
------------------------------------------------------------
Code: Select all
<form action="main.html" method="post">
<?php
//validate email
$email = $_POST['email'];
if (!strpos($email, "@") && substr_count($email, ".") != 1) {
echo "Invalid email! <a href = "question4d.html">Try again.</a>";
exit();
}
//validate tel no
$telNum = $_POST['telNum'];
if ($telNum{0} != "0") {
echo "Invalid tel number <a href = "question4d.html">Try again.</a>";
exit();
}
//greet user
$name = $_POST['name'];
$address = $_POST['address'];
echo "<h3>Hi $name!</h3> <br/>";
echo "$name <br/>";
echo "$address <br/>";
echo "$telNum <br/>";
echo "$email <br/><br/>";
//save to array
$arrayName[] = $name;
$arrayAddress[] = $address;
$arrayTelNum[] = $telNum;
$arrayEmail[] = $email;
//again
echo "<input type="submit" value="Again">";
?>How can I add new values to the existing arrays after the user click on Again button in process.php, add new data and click on Submit in main.html again?
Thank you.
?>