gpt4 book ai didi

php - 我为 mysql_connect() 使用什么密码和用户名?

转载 作者:行者123 更新时间:2023-11-29 01:55:59 25 4
gpt4 key购买 nike

好吧,你可能会说,但是,我对 MySQL 和 PHP 很陌生,我遇到了一个问题。在我的 connect.php 中,它连接到服务器,我不知道我的密码和用户名以及端口是否正确。现在它说端口 8080 的原因是因为我的其他 Web 开发程序之一正在使用端口 80 所以我进入 Apache 文件并更改为端口,所以现在当我登录 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
?>

登录.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>

最佳答案

您不需要使用 8080 只需使用 localhost 因为该端口号与 mysql 无关,但与 webserver 相关。为了解决网络服务器,您只需要像 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/en/book.mysqli.php

关于php - 我为 mysql_connect() 使用什么密码和用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29299219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com