当前位置:Gxlcms > PHP教程 > 向多个表填入相同字段的记要求指导

向多个表填入相同字段的记要求指导

时间:2021-07-01 10:21:17 帮助过:4人阅读

向多个表填入相同字段的记录求指导
这个为什么不对?

$username = $_POST['username'];
$password = $_POST['psd'];
$sex = $_POST['sex'];
$grade = $_POST['grade'];
$age = $_POST['age'];
$height=$_POST['height'];
$weight=$_POST['weight'];

//检查表单数据
if(!preg_match('/^[\w\x80-\xff]{3,15}$/', $username)){
exit('错误:用户名不符合要求!back');
}
if(strlen($password) < 6){
exit('错误:密码长度不符合要求!back');
}


include('conn.php');


$sql = "INSERT INTO user(username,password,sex,grade,age,height,weight)VALUES('$username','$password','$sex','$grade','$age','$height','$weight')";
INSERT INTO module1(username)VALUES('$username');
INSERT INTO module2(username)VALUES('$username');
INSERT INTO module3(username)VALUES('$username');
INSERT INTO module4(username)VALUES('$username');
INSERT INTO module5(username)VALUES('$username');
if(mysql_query($sql,$conn))
exit('注册成功!点击此处登入');
else
echo '抱歉,注册错误!:',mysql_error(),'
';
echo '点击此处返回 重试';

?>
------解决方案--------------------
哦 我才注意到 你的
$sql .= 'INSERT INTO module1(username)VALUES('$username');'
$sql .= 'INSERT INTO module2(username)VALUES('$username');'
$sql .= 'INSERT INTO module3(username)VALUES('$username');'
$sql .= 'INSERT INTO module4(username)VALUES('$username');'
$sql .= 'INSERT INTO module5(username)VALUES('$username');'
然后用mysqli::multi_query() 支持多语句执行 mysql只能是单语句执行 所以你插5次要执行 5次mysql_query

人气教程排行