创建注册表单时出错?

时间:2014-06-15 10:18:34

标签: php mysqli registration

**我创建了以下注册表** **

  

newuser.html

**

<form action="AddUser.php" method="POST">
<p>Enter A Username: </p>
<input type="text" name="User" maxlength="20" size="10">
<br />
<p>Enter your number: </p>
<input type="text" name="number" maxlength="40" size="10">
<br />
<input type="submit" value="Create Account">
</form>

然后将$ _Post数据转移到adduser.php,错误在此脚本中。 **

  

adduser.php

**     

//grabing our $_POST data from our form and assign them to variables...
$User = $_POST['User'];
$Phone = $_POST['number'];


//Check whether user put anything in the fields for user or phone
if (!$User || !$Phone) {
echo "You have not entered all the needed info. Please try again.";
exit();
}

// database connection
 $dbconnect = mysql_connect("localhost","root","");
if (!$dbconnect)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $dbconnect);

//Now inserting data into database
$sql = "INSERT INTO UsersTable (UserName, Phone)
VALUES ('".$User."', '".$Phone."')";

//Verify Successful Entry
if (mysqli_query($dbconnect,$sql)) {
echo "User Added Successfully";
} else {
echo "Error Creating User: " . mysqli_error($dbconnect);
}

echo "<br /><p>Please go to the main page to login now.</p>";
?>

这些是错误消息

**指警告:mysqli_query()期望参数1为mysqli,resource

  

在第28行的C:\ xampp \ htdocs \ test \ aaa \ new \ adduser.php中给出

     

警告:mysqli_error()期望参数1为mysqli,resource   在第31行的C:\ xampp \ htdocs \ test \ aaa \ new \ adduser.php中给出错误   创建用户:**

请告诉我一些调试方向.. 最后这是登录页面 **

  

的login.php

**

<?php
session_start();


$User = $_POST['User'];
$PW = $_POST['Phone'];

// database connection
$dbconnect = mysql_connect("localhost","root","");
if (!$dbconnect)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $dbconnect);

//cheaking for username and Phone matches in the database
$sql = "SELECT UsersTable.UserName, UsersTable.Phone
FROM UsersTable
WHERE UsersTable.Phone = '$phone'";
$result = $dbconnect->query($sql);


$_SESSION['verified_user'] = $User; //storing it in a SESSION

}
?>

和**

  

logout.php

**

<?php
session_start();

unset($_SESSION['verified_user']);
session_destroy();
echo "You are logged out.";
?>

请帮我调试代码

1 个答案:

答案 0 :(得分:0)

您正在使用两种不同的数据库API。 mysql_mysqli_。它们不兼容,选择一个并坚持下去。 (提示:不要选择mysql_,不推荐使用。)

相关问题