我是(初学者)在使用PHP更新MySQL中的两个表时遇到问题。使用字段'customerID'(自动递增)和'名称'来表“客户”。包含字段'email'和customerID的表格电子邮件。我使用一个简单的PHP联系表单来更新两个表的信息。我想从'customer'表中复制AI字段customerID,并使用customerID和用户输入的电子邮件地址更新第二个“email”表。如果我删除以下代码的第12行和第13行,并从查询中删除customerID位,它将数据插入到两个表中(当然,在电子邮件表中没有cusomerID)。如果我包含它,则不会更新任何数据。我知道它是我的语法,但我找不到它,额外的眼睛可以帮助!
<?php
include("connectionT.php");
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$query1 = "insert into customer (customerID, name) values (' ','".$name."')";
$result1 = mysqli_query($db_connect, $query1) or die("Error in SQL statement:" .mysqli_error());
mysql_query($sql);
$lastid = mysql_insert_id();
$query2 = "insert into email (customerID, email) values ($lastid,'".$email."')";
$result2 = mysqli_query($db_connect, $query2) or die("Error in SQL statement:" .mysqli_error());
mysqli_close($db_connect);
header("location:indexT.php?note=success");
这是功能最强大的代码
<?php
include("connectionT.php");
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$query1 = "insert into customer (name) values ('".$name."')";
$result1 = mysqli_query($db_connect, $query1) or die("Error in SQL statement:" .mysqli_error());
$query2 = "insert into email (email) values ('".$email."')";
$result2 = mysqli_query($db_connect, $query2) or die("Error in SQL statement:" .mysqli_error());
mysqli_close($db_connect);
header("location:indexT.php?note=success");