嗨所以我正在尝试使用mysql和php创建一个登录系统,但我不断收到错误
所示警告:mysql_connect():拒绝访问用户' testuser' @' localhost' (使用密码:YES)在第10行的E:\ PHP_Runner \ php \ root \ process.php中
<?php
$username = $_POST['user'];
$password = $_POST['pass'];
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
mysql_connect("localhost",$username, $password) or die("Could not connect to database");
mysql_select_db("users");
$result = mysql_query("select * from users where username = '$username' and password = '$password'")
or die("Failed to query database" .mysql_error());
$row = mysql_fetch_array($result);
if($row['username'] == $username && $row['password'] == $password){
echo "Login success !! welcome".$row['username'];
}else{
echo "Failed to login";
}
?>
答案 0 :(得分:0)
要连接到mysql db phpmyadmin或任何接口,您需要拥有不是用户登录凭据的mysql登录凭据,这通常是在安装mysql时设置的,或者您将使用默认值。现在这个设置凭据将替换mysql_connect("localhost", $TheSetUserNameForMysqlDb, $TheSetPasswordForMysqlDb)
我希望这个帮助
我建议不要使用默认
答案 1 :(得分:-2)
mysql connect应该像
<?php
$main_url="webpage";
$str = file_get_contents($main_url);
// Gets Webpage Title
if(strlen($str)>0)
{
$str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case
$title=$title[1];
}
// Gets Webpage Description
$b =$main_url;
@$url = parse_url( $b );
@$tags = get_meta_tags($url['scheme'].'://'.$url['host'] );
$description=$tags['description'];
// Gets Webpage Internal Links
$doc = new DOMDocument;
@$doc->loadHTML($str);
$items = $doc->getElementsByTagName('a');
foreach($items as $value)
{
$attrs = $value->attributes;
$sec_url[]=$attrs->getNamedItem('href')->nodeValue;
}
$all_links=implode(",",$sec_url);
//Gets Webpage images
require_once('C:\xampp\htdocs\simple_html_dom.php');
require_once('C:\xampp\htdocs\url_to_absolute.php');
$url='webpage'
$html=file_get_html('webpage');
foreach($html->find('img') as $element) {
echo url_to_absolute($url, $element->src), "\n";
}
$images=
// Store Data In Database
$host="localhost";
$username="root";
$password="";
$databasename="db";
$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);
mysql_query("insert into webpage_details values('$main_url','$title','$description','$all_links','$images')");
?>