mysqli_query():空查询mysqli_error()只需要1个参数,给定0

时间:2017-06-25 10:52:47

标签: php mysqli insert sql-insert undefined-index

我正在创建一个注册页面。表格包含电子邮件,密码,确认密码,学生证,名字,第二名,课程,性别和DoB。我希望页面收集该信息并将其存储在数据库中。

2个错误:

mysqli_query():空查询

mysqli_error()只需要1个参数,0给定

        $sql = mysqli_query($connection, "INSERT INTO tblaccounts (Email, Password, Student_ID, ID, FirstName, SecondName, Course, Gender, DoB) VALUES ('".$email."','".$password."','".$Student_ID."','".$id."','".$FN."','".$SN."','".$course."','".$gender."','".$dob."')"); 
        $result = mysqli_query($connection, $sql) or die("Database Connection Failed" . mysqli_error());  
        $count = mysqli_num_rows($result);






    <?php
    require_once 'connect.php';
    require_once 'logincheck.php';

        if (($_COOKIE['userID']) == null){
              //true
              //show sign in
              ?>
                <li><p><center><a class="btn btn-primary btn-lg" href="login.php" role="button">Sign In</a><center></p></li>
              <?php
              //show register button
              ?>
                <li><p><center><a class="btn btn-primary btn-lg" href="register.php" role="button">Register</a><center></p></li>
              <?php
        } else {
        //false
        //show 'logged in as'
              ?>
        <li><a href="#">Logged in as: <?php echo ($_COOKIE['user']) ?></a></li>
        <?php//show 'my profile'?>
        <li><a href="#">My Profile</a></li>
        <?php//show 'settings'.?>
        <li><a href="#">Settings</a></li>
        <li><p><center><a class="btn btn-primary btn-lg" href="logout.php" role="button">Sign Out</a><center></p></li>
            <!--<br/><a href ="login.php">Go back to the login screen.</a>-->

                        <!--logged in menu-->
            <!--<li><a href="#">User ID: <php echo ($_COOKIE['userID']) ?></a></li>-->
    </ul>
    <?php
        } 
    ?>

1 个答案:

答案 0 :(得分:0)

您正在执行一次查询,然后再尝试使用重新调整对象执行查询。将您的代码更改为:

$sql = "INSERT INTO tblaccounts (Email, Password, Student_ID, ID, FirstName, SecondName, Course, Gender, DoB) VALUES ('".$email."','".$password."','".$Student_ID."','".$id."','".$FN."','".$SN."','".$course."','".$gender."','".$dob."')"; 
        $result = mysqli_query($connection, $sql) or die("Database Connection Failed" . mysqli_error($connection));  
        $count = mysqli_num_rows($result);