duanhuihui2705 2016-09-09 13:51
浏览 44
已采纳

mysqli_query():第26行的/home/trainman/public_html/Register.php中的空查询

I am creating a sign up page. My code was working perfectly before on an intranet, but now, 5 years later I must use MySQL i.

What happens is I connect to the database using external PHP file, dblogin.php

<?php
$connection = mysqli_connect('mywebhost','username','password','db');
?> 

That bit works fine, as the login system works using this.

Then comes my registration system. It has been a while since I coded in PHP, mostly working using Wordpress now.

<?php
include 'dblogin.php';  

 if(isset($_GET['i'])){
        if($_GET['i'] == '1'){ //if we want to insert a new user
            $tblName="tblUsers";

        //Form Values into store
        $FirstName=$_POST['firstnamecreate'];
        $Surname=$_POST['Surnamecreate'];
        $Username=$_POST['UsernameCreate'];
        $UserType="stu"; //never mind this, it just seperates admins from standard users
        $Email=$_POST['EmailCreate'];
        $Password=$_POST['PasswordCreate'];



        $ExistingUserVerification = mysqli_query ($connection,"SELECT COUNT(*) as num FROM tblUsers WHERE UserName = $Username");

                    $UserResults = mysqli_query($connection,$ExistingUserVerification);




        if($UserResults[0] == 1){

            $CreatedStatus = "$Username already exists in the user database. Please choose a different Username.";

        }else{



            $sql="INSERT INTO $tblName(UserName, Password, UserType, FirstName, Surname, EmailAddress)VALUES('$Username', '$Password', '$UserType', '$FirstName', '$Surname', '$Email')";
            $result=mysqli_query($connection,$sql);
            if($result){
            $CreatedStatus = "$FirstName, you have registered successfully. Click " . "<a href=Login.php>". "HERE". "</a>" . " to login. " . "<br />"."Please note: Hacking of this site is not permitted.";
            }
            else {
            $CreatedStatus = "Unfortunately $Username was not created successfully. Please check your entry or check whether the user already exists.";
            }
        }
    }
}
?>

The problem i am getting is around the

$ExistingUserVerification = mysqli_query ($connection,"SELECT COUNT(*) as num FROM tblUsers WHERE UserName = $Username");

                        $UserResults = mysqli_query($connection,$ExistingUserVerification);

part. I have tried all sorts. With the current format, it results in:

Warning: mysqli_query(): Empty query in /home/trainman/public_html/Register.php on line 26

removing $connection results in it expecting 2 parameters and removing i says depricated.

Any help much appriciated. It has been a while since I last used php so sorry if the code is untidy. The select COUNT (*) checks if there is another user with the same username, if there isnt it will submit form values to the DB

  • 写回答

1条回答 默认 最新

  • dongmubi4375 2016-09-09 13:55
    关注

    This error is coming from the extremely simple fact that you are sending an empty query to mysqli. The query is empty. It's but an empty string. Nothing.

    So just check your variables.

    The second parameter to mysqli_query() should be a PHP string contains a legitimate SQL query. Anything else will cause an error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)