下面是我编写的代码,我一次只能插入一个表。请帮助我如何编写可以一次插入2个表的代码,我是php我的sql的新手,所以请帮助我详细感谢朋友,因为我从这个论坛一直得到非常好的回复..
<?php
include 'dateencode.php';
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "maindata";
$status="Data Request";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("<center>Connection failed: " . mysqli_connect_error() . "</center");
}
$f = $_POST['fname'];
$m = $_POST['mname'];
$l = $_POST['lname'];
$u =$_POST['uname'];
$pur = $_POST['pur'];
$sql = "INSERT INTO accounts (FirstName, MiddleName, LastName, FullName, Purpose) VALUES
('$f', '$m', '$l', '$u' ,'$pur');
INSERT INTO info (AccountName) VALUES ($u);";
if (mysqli_query($conn, $sql)) {
echo "<center>New record created successfully</center>";
echo "<center>Please wait you are redirecting to...</center>";
header("refresh:2;url=Datareq_form.php");
} else {
echo "Error Inserting into the database.: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>