duanguoyin7008 2014-09-03 16:28
浏览 47
已采纳

警告:mysql_real_escape_string(),是什么意思? [关闭]

I get these errors:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'a2955851'@'localhost' (using password: NO) in /home/a2955851/public_html/register.php on line 25

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'a2955851'@'localhost' (using password: NO) in /home/a2955851/public_html/register.php on line 26

and i get these errors:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a2955851/public_html/register.php on line 25

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a2955851/public_html/register.php on line 26

there is my code:

      <!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> &bullet;     
                <a href="https://www.google.fi/">Kaikkee</a> &bullet; 
                <a href="https://www.mediafire.com/">Lataukset</a>  </div>
            </h3>
        </div>

        <div class="jonne"> </div>
        <script src="javascript/jquery.js"></script>
    </body>
</html>

What did I do wrong? i use 000webhost and i'm noob. My english skill is very bad, sorry.

  • 写回答

1条回答 默认 最新

  • doushishi2415 2014-09-03 16:33
    关注

    Need to connect before real_escape. I suggest you to use mysqli. You can try this.

    $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.";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么