mysql_connect()使用什么密码和用户名?

诺亚·克拉克(Noah Clark)

好的,您可能会知道,但是,我对MySQL和PHP还是很陌生,并且遇到了问题。在connect.php连接到服务器的my中,我不知道我的密码和用户名是否与港口是正确的。现在说8080端口的原因是因为我的其他Web开发程序之一正在使用80端口,所以我进入了Apache文件并更改为port,所以现在登录phpMyAdmin时必须输入localhost:8080我不知道这是否与mysql_connect,也检查了phpMyAdmin并说我的用户名是root,密码为空。空密码会引起混乱MySQL_connect()吗?谢谢,这是代码:

connect.php

<?php 
//This file allows me to easily connect to my database

mysql_connect("localhost:8080", "root", "");//connects to database, params are ("servername", "username", "password");
mysql_select_db("membersystem");//selects the table from db
?>

login.php

<?php 
error_reporting (E_ALL ^ E_NOTICE);//saves us from getting undefined index error

session_start();//makes it a sesion based system
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>

</head>

<body>
     <!--the action='./login.php' tells the page where its gonna send the info, and the method='post' makes it so it dosent show the users personal info -->
    <?php 
        $form = "<form action='./login.php' method='post'>
            <table>
                <tr>
                    <td>Username</td>
                    <td><input type='text' name='user'/></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type='password' name='password'/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type='submit' name='loginbtn' value='Login'/></td>
                </tr>
            </table>
        </form>";

        if($_POST['loginbtn']){//if loginbtn pressed
                $user = $_POST['user'];//gets the username from text field from the form above
                $password = $_POST['password'];//gets the password from text field from the form above

                if($user){//checks if the username field from the form has been filled out
                    if($password){//checks if the password field from the form has been filled out
                        require("connect.php");//connects to db through connect.php

                        $password = md5(md5("gshgrYY665f".$password."gr76TH967G"));//encrypts the password 

                        //echo "$password"; echos the hash for password (5f8b1a8d8f2471a2c7c17e0058873447 )

                        $query = mysql_query("SELECT * FROM users WHERE username='$user' ");//checks if the username is found in database
                        $numrows = mysql_num_rows($query);
                        if($numrows == 1){
                                $row = mysql_fetch_assoc($query);//gets the query associated with the php
                                $dbid = $row['id'];//gets the id from db
                                $dbuser = $row['username'];//gets the username from db
                                $dbpass = $row['password'];//gets the password from db
                                $dbactive= $row['active'];//gets the active value from db

                            if($password == $dbpass){
                                if($dbactive == 1){

                                        //sets session info
                                        $_SESSION['userid'] = $dbid;
                                        $_SESSION['username'] = $dbuser;

                                        echo "you have been logged in as <b>$dbuser</b>. <a href='./member.php'>Click here</a> to go to member page";
                                    }
                                    else
                                        echo "You must activate your account to login. $form";



                                }
                                else
                                    echo "You didnt enter the right pass. $form";   
                            }
                            else
                                echo "The username you entered was not found. $form";

                        mysql_close();//closes connection
                    }
                    else
                        echo "You must enter your password. $form";
                }
                else
                    echo "You must enter your username. $form";
            }
            else
                echo $form;
    ?>
</body>
</html>
墨C天堂

您不需要使用8080简单使用,localhost因为该端口号与mysql不相关,但与Web服务器相关。为了只访问网络服务器,您需要像localhost:8080/project-name/

并且不要使用mysql_*方法。将来会失望的。mysqli

 $con = new mysqli("localhost","root","","membersystem") or die('Connection failed');
 $result = $con->query("Your query here");

否则您可以在mysqli_*函数中使用相同的过程方法但是我更喜欢与面向对象的php一起使用。

请参阅文档。http://php.net/manual/zh/book.mysqli.php

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PHP登录“无效的用户名和密码”使用MySQL

orientdb connect无效的密码和用户名

使用python向用户询问用户名和密码

我的登录用户名和密码是什么?

什么是Grafana登录页面默认的用户名和密码?

SonarQube的默认用户名和密码是什么?

MongoDB的默认用户名和密码是什么?

如何获取我的MySQL用户名和密码?

如何获取Python MYSQL连接用户名和密码?

在应用 Azure 用户名和密码中重置 MySQL

如何从 mysql netbeans 验证用户名和密码

如何使用WAMP登录phpMyAdmin,用户名和密码是什么?

MySQL转储,使用正确的用户名和密码拒绝访问1045

php mysql会话使用错误的用户名和密码重定向到主页

首次登录Apache Airflow要求输入用户名和密码,用户名和密码是什么?

首次登录Apache Airlfow要求输入用户名和密码,用户名和密码是什么?

使用Azure Key Vault存储用户名和密码

如何使用用户名和密码连接LDAP?

使用并行数组的用户名和密码

使用pkgcloud在OpenStack中验证用户名和密码

使用用户名和密码进行密钥验证

如何使用Mercurial保存用户名和密码?

使用用户名和密码的Python github Pull

使用RCurl发布用户名和密码

在python中使用硒填充用户名和密码

使用机械化输入用户名和密码

使用Springboot在https url中的用户名和密码

使用Ansible创建新的用户名和密码

使用用户名和密码访问Kubernetes API