繁体   English   中英

MySQL查询麻烦:上传

[英]Mysql query trouble: uploading

我正在尝试最后一个小时解决此问题。 我的表格很长,我正在尝试将信息上传到mysql数据库。 进桌子我做了。 这是我正在使用的mysql查询:

mysql_query("INSERT INTO `users_temp`(`first_name`, `surname`, `birthday`, `nationality`, `email`, `mobile`, `landline`, `address`, `town`, `post_code`, `country`, `password`, `code_conf`) VALUES ([$f_name],[$s_name],[$bday],[$nationality],[$email],[$mobile],[$landline],[$address],[$town],[$post_code],[$country],[$pass],[$conf_code])");

如果有人看到任何问题为什么不起作用请告诉我。 谢谢...

$f_name         = $_POST["f_name"];
$s_name         = $_POST["s_name"];
$pass           = $_POST["pass"];
$birthday       = $_POST["bday"];
$nationality    = $_POST["nationality"];
$email          = $_POST["email"];
$mobile         = $_POST["mobile"];
$landline       = $_POST["landline"];
$address        = $_POST["address"];
$town           = $_POST["town"];
$post_code      = $_POST["post_code"];
$country        = $_POST["country"];

$conf_code      = substr(md5(uniqid(rand(), true)), 1, 70);

include("connect_into_mysql.php");
mysql_select_db("jzperson_edu", $conn);

$res_01 = mysql_query("SELECT * FROM users WHERE email='$email'");
$count_01 = mysql_num_rows($res_01);

if($count_01==0)
{
mysql_query("INSERT INTO users_temp ('first_name','surname','birthday','nationality','email','mobile','landline','address','town','post_code','country','password','code_conf') VALUES ('$f_name','$s_name','$bday','$nationality','$email','$mobile','$landline','$address','$town','$post_code','$country','$pass','$conf_code')");
header("Location: home.php");
}else{echo "This email is already registered. If you lost your password you can reset it here.";}

1 /您必须了解SQL注入:请阅读本文 用mysql_real_escape_string封装所有$ _POST数据,例如:

$f_name         = mysql_real_escape_string($_POST["f_name"]);

2 / MySQL将很快过时,请参见此处的红框。

3 /在所有标头之后,放置一个die()(否则,代码将继续执行到最后,并且如果禁用了客户端的浏览器重定向,则他可能会看到一些未授权的内容)。

4 /不要在一行中写很长的请求,这样可以避免麻烦并简化工作。 并对其进行调试,请在末尾添加“ or die(mysql_error()) ”,该消息将显示一条消息,帮助您大量获取解决方案。

mysql_query("
INSERT INTO users_temp (
    'first_name','surname','birthday',
    'nationality','email','mobile',
    'landline','address','town',
    'post_code','country','password',
    'code_conf'
) VALUES (
    '$f_name','$s_name','$bday',
    '$nationality','$email','$mobile',
    '$landline','$address','$town',
    '$post_code','$country','$pass',
    '$conf_code'
)
") or die(mysql_error());

顺便说一句,您正在检查用户表,然后将其插入到user_tmp表中。 这样您可能会遇到冲突麻烦,不是吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM