向多个表填入相同字段的记要求指导
程序员文章站
2024-02-20 10:42:22
...
向多个表填入相同字段的记录求指导
这个为什么不对?
$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) 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
这个为什么不对?
$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) 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
相关文章
相关视频
- 关于中英数字混的字串符分割问题_PHP教程
- 应用PHP标签模板实现什么任务_PHP教程
- php入门教程 精简版_PHP教程
- php4的session功能评述(三)_PHP教程
- 向多个表填入相同字段的记要求指导