php抓取网页数据插入数据库(后重定向-获取后将浏览器重定向回最终目的地。)
优采云 发布时间: 2022-02-27 23:07php抓取网页数据插入数据库(后重定向-获取后将浏览器重定向回最终目的地。)
发布重定向 - 获取。成功提交到数据库后,将浏览器重定向回最终目的地。
首先防止注入攻击:
include('connection.php');
$username = mysql_real_escape_string($_POST['username']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$securityq = mysql_real_escape_string($_POST['security_q']);
$securitya = mysql_real_escape_string($_POST['security_a']);
// Use filtered values here, never direct from $_POST!!!!!
$sql="INSERT INTO candidate_register_table (username, name, email, password, security_q, security_a)
VALUES ('$username','$name','$email','$password','$security_q','$security_a')";
if (!mysql_query($sql,$con))
{
// Don't die(). Instead redirect with error.
$err=1;
}
mysql_close($con);
// Set an error parameter if there was a problem...
// this is optional, since a failure of mysql_query() would indicate a code problem
// rather than a problem with the user's input.
if (isset($err)) {
// And redirect back to the form with the error in the querystring
header("Location: http://example.com/form.php?err=1");
exit();
}
else {
// No error...
// And redirect back to the form...
header("Location: http://example.com/form.php");
exit();
}
在表单页面上,如果要向用户显示错误,可以执行以下操作:
if (isset($_GET['err'])) {
echo "an error occurred...";
}
设置错误信息为$_SESSION,显示在屏幕上后完成unset()
发布重定向 - 获取。成功提交到数据库后,将浏览器重定向回最终目的地。首先防止注入攻击:include('connection.php'); $username = mysql_real_escape_string($_POST['username']);$name = ...