注册表格不起作用 - php错误

时间:2013-12-17 17:04:19

标签: php mysql

我正在尝试为我的网站制作一个注册表单 表单有效,但是当我提交时,它会给出这些错误:

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/toonbox/public_html/Rework/register.php on line 28

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/toonbox/public_html/Rework/register.php on line 29

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/toonbox/public_html/Rework/register.php on line 30

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/toonbox/public_html/Rework/register.php on line 31
Error: Please fill in the form!
Notice: Undefined variable: row in /home/toonbox/public_html/Rework/register.php on line 44

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/toonbox/public_html/Rework/register.php on line 48
Unable to access the table!

继承代码

    <?php
//REGISTER.PHP
//By Sheriff Reggie.

//temp
//used to check the errors in the script
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start(); //starts php session

require "register.inc.php"; //include the config file

if(isset($_SESSION['username'])){
   header("location: play.php");
}

if(isset($_POST['submit']))
{

//variables
$userPOST = isset($_POST['username']) ? $_POST['username'] : '';
$passPOST = $_POST['pass'];
//$passchk = $_POST['pass']; //to do soon
$emailPOST = $_POST['email'];
$keyPOST = $_POST['key'];

$user = mysqli_real_escape_string($userPOST, $dbcon);
$pass = mysqli_real_escape_string($passPOST, $dbcon);
$email = mysqli_real_escape_string($emailPOST, $dbcon);
$key = mysqli_real_escape_string($keyPOST, $dbcon);

if($user == "" || $pass = "" || $email = "" || $key = "")
{
  echo "Error: Please fill in the form!";
}

else
{
     $row = mysqli_num_rows($query);
     $query = mysql_query("SELECT * FROM users WHERE username = '$user'",$dbcon) or die ("Unable to access the table!");

    }
    if($row == 1)
      echo "User already exist. Please choose a different username!";
    {
    //verify key is valid
    $querykey = mysqli_query("SELECT * FROM users WHERE keys = '$key'", $dbcon) or die ("Unable to access the table!");
    $rowkey = mysqli_num_rows($querykey);
    if(!$rowkey == 1)
      echo "Key isn't valid. Try again!";
    }
    if($rowkey == 1)
    {
     $reg = mysql_query("INSERT INTO users (id, username, password, email, key) VALUES (null, '$user', '$pass', '$email', '$key'),$dbcon")  or die ("Cannot register. An error occured!");
     echo "Sucessfully registered!";
   }
}
?>
<html>
<div align="center">
<!-- Yes joe, ill add style later. Lemme just test this !-->
<form name="register" method="post" action="register.php">
<input name="user" type="text" id="username" value="Your Username"><br><br>
<input name="pass" type="password" id="pass" value="Your Password"><br><br>
<input name="email" type="text" id="email"  value="Your E-mail"><br><br>
<input name="key" type="text" id="key"  value="An Valid Alpha Key"><br><br>
<input type="submit" name="submit" value="Register">
</div>
</form>
</html>

我尝试过并尝试在代码中找不到错误。 我真的很想找到它的来源。 有什么方法可以解决这个问题吗?

编辑1: 我想我发现了原因。 我忘了在我的include文件中将mysql更改为mysqli 不管怎样,谢谢:)

1 个答案:

答案 0 :(得分:0)

试试这个,您使用$query = mysql_query代替mysqli_mysqli_num_rows来自选择$query

语法: mysqli_real_escape_string ( mysqli $link , string $escapestr )

更正语法:

mysqli_real_escape_string($dbcon, $userPOST);

$query = mysqli_query($dbcon, "SELECT * FROM users WHERE username = '$user'") or die ("Unable to access the table!");

$row = mysqli_num_rows($query);
相关问题