我收到这些错误:
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:/home/a2955851/public_html/register.php上的用户'a2955851'@'localhost'(使用密码:NO)拒绝访问25
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:/home/a2955851/public_html/register.php上的用户'a2955851'@'localhost'(使用密码:NO)拒绝访问26
我得到了这些错误:
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:无法在第25行的/home/a2955851/public_html/register.php中建立指向服务器的链接
警告:mysql_real_escape_string()[function.mysql-real-escape-string]:无法在第26行的/home/a2955851/public_html/register.php中建立指向服务器的链接
有我的代码:
<!doctype html>
<html lang"fi">
<head>
<link rel="icon" type='image/png' href='images/logo.png'>
<title> ASD</title>
<link href="css/styles.css" type="text/css" rel="stylesheet">
</head>
<body>
<!--reg alkaa-->
<form action="register.php" method="post">
<p><input type="text" name="username" placeholder="Username">
<p><input type="email" name="email" placeholder="Email">
<p><input type="password" name="pass" placeholder="Password">
<p><input type="password" name="pass1" placeholder="Password">
<p><input type="submit" name="submit" value="Register">
</form>
<?php
if (isset($_POST['submit'])) {
$username = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['pass']);
$pass1 = mysql_real_escape_string($_POST['pass1']);
$email = mysql_real_escape_string($_POST['email']);
if ($username && $pass && $pass1 && $email) {
if ($pass==$pass1) {
$connect = mysql_connect("mysql13.000webhost.com","a2955851_SW","********");
mysql_select_db("a2955851_SW");
$query = mysql_query("INSERT INTO users VALUES('$username','$pass','$email');");
echo "You have been registered.";
} else {
echo "Password must match.";
}
} else {
echo "All fields are required.";
}
}
?>
<!--reg loppuu-->
<Center>
<a href="index.php">
<h1> ASD </h1>
</center>
</a>
<div id="main">
<h3>
<div class="menu"> <a href="index.php">Etusivu</a> •
<a href="https://www.google.fi/">Kaikkee</a> •
<a href="https://www.mediafire.com/">Lataukset</a> </div>
</h3>
</div>
<div class="jonne"> </div>
<script src="javascript/jquery.js"></script>
</body>
</html>
我做错了什么?我使用000webhost,我是菜鸟。我的英语技能非常糟糕,抱歉。
答案 0 :(得分:0)
需要在real_escape之前连接。我建议你使用mysqli
。你可以试试这个。
$connect = mysqli_connect("mysql13.000webhost.com","a2955851_SW","********");
if(isset($_POST['submit']))
{
$username = mysqli_real_escape_string($connect, $_POST['username']);
$pass = mysqli_real_escape_string($connect, $_POST['pass']);
$pass1 = mysqli_real_escape_string($connect, $_POST['pass1']);
$email = mysqli_real_escape_string($connect, $_POST['email']);
if($username && $pass && $pass1 && $email)
{
if($pass==$pass1)
{
mysqli_select_db($connect, "a2955851_SW");
$query = mysqli_query($connect, "INSERT INTO users VALUES('$username','$pass','$email');");
echo "You have been registered.";
}
else
{
echo "Password must match.";
}
}
else
{
echo "All fields are required.";
}
}