我试图重定向到感谢网页后,在mysql上使用存储的数据 header("Location: success.html"); exit;
但是当我打开这个链接时,它会自动进入success.html页面,而不需要在表单和mysql上输入或存储任何数据。
<?php
$con=mysqli_connect("localhost","root","","vdl");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['submit'])) // Fetching variables of the form which travels in URL
{
$company_name = $_POST['company_name'];
$since = $_POST['since'];
$strength = $_POST['strength'];
$head_quarter = $_POST['head_quarter'];
if($company_name !=''||$since !='')
{
mysqli_query($con,"insert into digital_library(company_name, since, strength, head_quarter) values ('$company_name', '$since', '$strength', '$head_quarter')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
mysqli_close($con);
}
else
{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
header("Location: success.html");
exit;
?>
2条答案
按热度按时间gdx19jrr1#
请使用pdo或mysqli。我刚刚编辑了您现有的代码,以便您在成功插入后重定向到成功页面。
ttisahbt2#