我需要上传表单的插入数据,并在提交时转到“感谢页面”。我尝试了一些方法,但只能成功使用一种方法,但不能同时使用两种方法。该网站在Wordpress和XAMPP上。以下代码只是重定向,但是如果我删除onsubmit属性,它将提交但不会重定向。<script> function redirect(){ window.location.replace("localhost/concurs/thank-you-page"); return false; }</script><?php $x=new mysqli("localhost", "root", ""); if ($x->connect_error) { die("Connection failed: " . $x->connect_error); } $y=mysqli_select_db($x,"concurs"); $Prenume = ""; $Nume = ""; $email = ""; $tel = ""; $Prenume= isset($_POST['firstname']) ? $_POST['firstname'] : ''; $Nume= isset($_POST['lastname']) ? $_POST['lastname'] : ''; $email= isset($_POST['email']) ? $_POST['email'] : ''; $tel= isset($_POST['tel']) ? $_POST['tel'] : ''; $z = ""; if($Prenume!=null && $Nume!=null && $email!=null) $z=mysqli_query($x,"INSERT INTO concurs.wp_formular (Prenume, Nume, email, tel) VALUES ('$Prenume', '$Nume','$email', '$tel')"); mysqli_close($x); ?><form data-validate="parsley" data-parsley-validate="" id="myForm" method="post" action="" onsubmit="return redirect()"> <button type="submit" class="form_submit LatoBlack" id="submit"> Submit </button></form>
1 回答
子衿沉夜
TA贡献1828条经验 获得超3个赞
试试这个
$query=mysqli_query($con,"INSERT INTO `table` (name,mobile) VALUES('$name','$mobile')");
if($query){
?>
<script>
window.location.href="thankyou.php";
</script>
<?php
}else{
echo mysqli_error();
}
- 1 回答
- 0 关注
- 152 浏览
添加回答
举报
0/150
提交
取消