我正在进行一个简单的用户注册这给我一些错误,我就像1小时看到其他问题和答案但没有什么可以解决我的问题,所以这里是
第一个我的register.php
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysqli_real_escape_string($_POST['username']);
$password = md5(mysqli_real_escape_string($_POST['password']));
$email = mysqli_real_escape_string($_POST['email']);
$checkusername = mysqli_query("SELECT * FROM users WHERE Username = '".$username."'");
if(mysqli_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
}
else
{
$registerquery = mysqli_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
if($registerquery)
{
echo "<h1>Success</h1>";
echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
}
else
{
?>
<h1>Register</h1>
<p>Please enter your details below to register.</p>
<form method="post" action="register.php" name="registerform" id="registerform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<label for="email">Email Address:</label><input type="text" name="email" id="email" /><br />
<input type="submit" name="register" id="register" value="Register" />
</fieldset>
</form>
<?php
}
?>
现在我的conexion.php
<?php
//Conexión a la base de datos
$servidor = "localhost"; //Nombre del servidor
$usuario = "myuser"; //Nombre de usuario en tu servidor
$password = "mypass"; //Contraseña del usuario
$base = "db_maquinas"; //Nombre de la BD
//conection:
$link = mysqli_connect("$servidor","$usuario","$password","$base") or die("Error " . mysqli_error($link));
?>
这是给我的错误
警告:mysqli_real_escape_string()正好需要2个参数,1在第14行的C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出
警告:mysqli_real_escape_string()正好需要2个参数,1在第15行的C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出
警告:mysqli_real_escape_string()需要2个参数,第16行在C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出
警告:mysqli_query()需要至少2个参数,1在第18行的C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出
警告:mysqli_num_rows()要求参数1为mysqli_result,在第20行的C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出null
警告:mysqli_query()需要至少2个参数,1在第27行的C:\ xampp \ htdocs \ maquinas2000 \ paginas \ register.php中给出
我知道是关于mysqli,但我试图弄清楚,但没有发生同样的错误..之前给了我更多的错误......我解决了一些但仍然是那些错误... THX
答案 0 :(得分:0)
您应该简单地使用$link
作为这些函数的参数:
mysqli_query($link, "your query here");
和
mysqli_real_escape_string ( $link , 'value to escape' );