0

我正在尝试将用户名、密码和电子邮件插入到一个数据库的表中,并插入相同的用户名,但不是密码和电子邮件,而是设置为 1(通知行)。这是我的代码:

<?php
**$con= new mysqli("localhost","root","","users");
$con2 = new mysqli("localhost","root","","notification");**
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$hpassword = hash( 'sha512', $_POST['password'] );
$eusername = mysqli_real_escape_string( $con, $_POST['username'] );
$eemail = mysqli_real_escape_string( $con, $_POST['email'] );
$fusername = str_replace(' ', '', $eusername);
$check = "SELECT * FROM users WHERE username='$fusername'";
$result = mysqli_query($con, $check);
$data = mysqli_fetch_array($result, MYSQLI_NUM);
if($data[0] > 1) {
    echo "User Already in Exists<br/>";
}

else
{
    **$con->query="INSERT INTO users (username, password, email) VALUES ('$fusername','$hpassword','$eemail')";
    $con2->query="INSERT INTO notification (username, notifications) VALUES ('$fusername','1')";**
    if (mysqli_query($con,$con->query))
    {
    if (mysqli_query($con,$con2->query))
    {
    }
    else
    {
    }
    sleep(2);
    header("location:login.php");
    }
    else
    {
        echo "Error: Username already exists.<br/>";
    }
}
mysqli_close($con);
?> 

目前,它只将数据提交到用户数据库。不是通知数据库。

4

1 回答 1

1

在您的第二个 mysqli_query 调用中,您使用与第一个相同的连接$con。而是使用$con2.

if (mysqli_query($con,$con->query))
{
if (mysqli_query($con2,$con2->query))    // <--- used $con2 here
{
}
于 2013-07-24T02:06:40.277 回答