我是 PHP 新手,刚刚完成了一组用于连接、注册和登录的代码。在 MySQL 上一切正常。现在我从 MySQL 切换到 MySQLi,我遇到了问题。我需要一些关于这个问题的建议;我只是在 mysql 之后添加一个“i”还是我也必须改变一些事情?
例如:
//ob
ob_start();
//connect to database
$error = "Problem connecting";
mysql_connect('-------','------','------') or die($error);
mysql_select_db('-------') or die($error);
它像那样工作正常,但是当我将其更改为: //ob ob_start();
//connect to database
$error = "Problem connecting";
mysqli_connect('-------','------','------') or die($error);
mysqli_select_db('-------') or die($error);
如果我添加“i”或
//ob
ob_start();
//connect to database
$error = "Problem connecting";
mysqli_connect('-------','------','------','db') or die($error);
也不像上面那样工作。我想知道我是否做错了什么。
谢谢,非常感谢您的帮助,因为我是 PHP 的超级菜鸟。
注册.php
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
include 'connect.php';
if ($_POST)
{
//get form data
$username = addslashes(strip_tags($_POST['username']));
$password = addslashes(strip_tags($_POST['password']));
$email = addslashes(strip_tags($_POST['email']));
if (!$username||!$password||!$email)
echo "Please fill out all fields";
else
{
//encrypt password
$password = md5($password);
//check if username already taken
$check = mysql_query("SELECT * FROM Test WHERE username = '$username'") or die(mysql_error());
if (mysql_num_rows($check)>=1)
echo "Username already taken";
else
{
//send activation email
$to = $email;
$subject = "Activate your account";
$headers = "From: abc.info";
$body = "Hello $username,\n\nYou registered and
need to activate your account. Click the link below or
paste it into the URL bar of your browser\n\nhttp://testing.com/activation.php!";
if (!mail($to,$subject,$body,$headers))
echo "We couldn't sign you up at this time. Please try again later.";
else
{
//register into database
mysql_query("INSERT INTO Test (username,password,email) VALUES
('$username','$password','$email');") or die(mysql_error());
echo "1 record added";
}
}
}
}
else
{
?>
<form action='register.php' method='POST'>
Choose username:<br />
<input type='text' name='username'><p />
Choose password:<br />
<input type='password' name='password'><p />
Email:<br />
<input type='text' name='email'><p />
<input type='submit' name='register' value='Register'>
</form>
<?php
}
?>