Reputation: 13
I got a problem storing my form values. My goal is to submit my first form, save the values inside a variable, redirect to my second form and submit/store all form values inside my database(SQL).
HTML
<form action="process.php" class="form" method=POST name="firstform" onsubmit="return chkForm()">
<label id="form_title">Bevor wir anfangen können, benötigen wir noch ein paar Informationen von Ihnen:</label>
<br/>
<br/>
<label for="name">Benutzername</label>
<input type="text" id="name" name="name" value="">
<label for="email">Email</label>
<input type="email" id="email" name="email" value="">
<button type="submit" name="submit" value="abschicken">Eingaben absenden</button>
</form>
process.php
try {
$connect = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $pass);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connect->beginTransaction();
if (!empty($_POST['firstform'])) {
$alias = $_POST['name'];
$mail = $_POST['email'];
echo '<script type="text/javascript">window.document.location.href = "http://www.example.de/form2.php";</script>';
exit;
}
if(isset($_POST['fullform'])){
$connect->exec("INSERT INTO user (name, email, answer_0, answer_1, answer_2, answer_3, answer_4, answer_5, answer_6, answer_7, answer_8, answer_9, answer_10, answer_11, answer_12, answer_13, answer_14, answer_15, answer_16, answer_17) VALUES ('$alias', '$mail', '$_POST[answer_0]', '$_POST[answer_1]', '$_POST[answer_2]', '$_POST[answer_3]', '$_POST[answer_4]', '$_POST[answer_5]', '$_POST[answer_6]', '$_POST[answer_7]', '$_POST[answer_8]', '$_POST[answer_9]', '$_POST[answer_10]', '$_POST[answer_11]', '$_POST[answer_12]', '$_POST[answer_13]', '$_POST[answer_14]', '$_POST[answer_15]', '$_POST[answer_16]', '$_POST[answer_17]');");
}
$connect->commit();
echo "Danke Für Ihre Teilnahme";
echo $_POST['email'];
exit;
Why is my script not redirecting after i saved the values into $alias and $mail.
Upvotes: 0
Views: 55
Reputation: 1429
On a fast search on the site, i found that and could help you.
// similar behavior as an HTTP redirect:
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link:
window.location.href = "http://stackoverflow.com";
How to redirect to another webpage in JavaScript/jQuery?
Upvotes: 0
Reputation: 498
You can use header("location:http://www.example.de/form2.php");
instead of javascript.
If you want use javascript then use window.location
instead of window.document.location.href
echo "<script type="text/javascript">window.location = 'http://www.example.de/form2.php';</script>";
Upvotes: 1