我是mysql和php的新手,我试图只使用一个表单将值插入两个不同的表中
它一直在说 mysqli_num_rows()期望参数1为mysqli_result mysqli_fetch_array()期望参数1为mysqli
<?php
include('dbconn.php'); // Database connection and settings
if (isset($_POST['Submit'])) {
$username = $_POST["username"];
$password = $_POST["password"];
$firstname = $_POST["firstname"];
$middlename = $_POST["middlename"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$mobile = $_POST["mobile"];
$telephone = $_POST["telephone"];
$username = trim(mysqli_escape_string($con, $username));
$password = trim(mysqli_escape_string($con, $password));
$firstname = trim(mysqli_escape_string($con, $firstname));
$middlename = trim(mysqli_escape_string($con ,$middlename));
$lastname = trim(mysqli_escape_string($con, $lastname));
$email = trim(mysqli_escape_string($con, $email));
$mobile = trim(mysqli_escape_string($con, $mobile));
$telephone = trim(mysqli_escape_string($con, $telephone));
$sql = "SELECT accholder_Username FROM tbl_accholder WHERE accholder_Username='$username'";
$sql2 = "SELECT contacts_email FROM tbl_contacts WHERE contacts_email='$email'";
$result = mysqli_query($con, $sql);
$result2= mysqli_query($con, $sql2);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$row2 = mysqli_fetch_array($result2,MYSQLI_ASSOC);
if (mysqli_num_rows($result && ) == 1) {
echo "Sorry...This Username already exist..";
}
else if (mysqli_num_rows($result2) == 1) {
echo "Sorry...This Email already exist..";
}
else {
$query = mysqli_query($con, "INSERT INTO tbl_accholder( accholder_Fname, accholder_Mname, accholder_Lname, accholder_Username, accholder_Password)
VALUES ('$firstname', '$middlename', '$lastname','$username','$password')");
$query2 = mysqli_query($con, "INSERT INTO tbl_contacts( contacts_email, contacts_mobile, contacts_telephone, acchold_ID)
VALUES ('$email', '$mobile', '$telephone')");
if ($query && $query2) {
echo "Thank You! you are now registered.";
}
}
}
?>
答案 0 :(得分:0)
您的$ sql变量包含无效的SQL语句,因为您尝试连接两个单独的SELECT查询。