向多个表填入相同字段的记录求指导
这个为什么不对?
$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 '点击此处返回 重试';
?>
回复讨论(解决方案)
测试成功了吗?不成功报什么错误?
今天晚上之前必须要交的作业,
reg.php的开头加上 session_start();
session start 对用户名定义变量我已经在登入页面写了,这样打重可以吗?
在或者是在注册和登入页面分别用两个session变量操作吗?
就在reg.php里面先定义再注销。是这样吗?
在或者是在注册和登入页面分别用两个session变量操作吗?
就在reg.php里面先定义再注销。是这样吗?
刚才不好意思 那个session_start不是你的错误 我是回答别人的帖子的 不小心回答道你这了
echo '抱歉,注册错误!:'.mysql_error().'
'; 你的错误24行 应该是 里面的 逗号改成句号
应该不是这个错误导致的。因为我在插入第2-5个insert into 语句()也就是说只有一个insert 语句是正常的。
哦 我才注意到 你的
$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
应该不是这个错误导致的。因为我在插入第2-5个insert into 语句()也就是说只有一个insert 语句是正常的。
谢谢,我去试一下
我不会改,怎么改都错。。。就是if语句那里
你还是去看手册mysqli的用法 还需要php支持mysqli扩展的
不会的话还是老老实实写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')";
$sql1=INSERT INTO module1(username)VALUES('$username');
$sql2=INSERT INTO module2(username)VALUES('$username');
$sql3=INSERT INTO module3(username)VALUES('$username');
$sql4=INSERT INTO module4(username)VALUES('$username');
$sql5=INSERT INTO module5(username)VALUES('$username');
$sql6=INSERT INTO module5(username)VALUES('$username');
$result=mysql_query($sql,$conn);
$result1=mysql_query($sql1,$conn);
$result2=mysql_query($sql2,$conn);
$result3=mysql_query($sql3,$conn);
$result4=mysql_query($sql4,$conn);
$result5=mysql_query($sql5,$conn);
$result6=mysql_query($sql6,$conn);
if($result && $result2 && $result3 &&$result4 && $result5 && $result6)
exit('注册成功!点击此处登入');
else
echo '抱歉,注册错误!:',mysql_error(),'
';
echo '点击此处返回 重试';
?>
$sql1=”INSERT INTO module1(username)VALUES('$username')“; 注意细节 没有银行 分号也是错误的 这些细节都不想说了
你这代码好多细节啊 (是英文的括号 连接符是点号不是逗号 这些都是最最最基本的啊
没有啊,调试过了,可能是粘贴过来就转换成这样了。
anyway,真的谢谢你了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
