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.

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

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败