向多个表填入相同字段的记录求指导
这个为什么不对?
<?php
$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('错误:用户名不符合要求!<a href="javascript:history.back(-1);">back</a>');
}
if(strlen($password) < 6){
exit('错误:密码长度不符合要求!<a href="javascript:history.back(-1);">back</a>');
}
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('注册成功!点击此处<a href="login.html">登入</a>');
else
echo '抱歉,注册错误!:',mysql_error(),'<br />';
echo '点击此处<a href="javascript:history.back(-1);">返回</a> 重试';
?>
------解决方案--------------------哦 我才注意到 你的
$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