Php 无法连接到MySQL数据库错误

Php 无法连接到MySQL数据库错误,php,mysql,database,web,Php,Mysql,Database,Web,可能重复: 我主持了一个bux网站CrimsonBux.Com。所有的工作都非常出色的脚本。我只有一个密码恢复页面的问题。在页面上输入电子邮件地址和验证码后,用户将被重定向到此页面。在recover.php页面中,用户面临错误。下面列出了错误 Warning: mysql_query() [function.mysql-query]: Access denied for user 'crimst1d'@'localhost' (using password: NO) in /home/crim

可能重复:

我主持了一个bux网站CrimsonBux.Com。所有的工作都非常出色的脚本。我只有一个密码恢复页面的问题。在页面上输入电子邮件地址和验证码后,用户将被重定向到此页面。在recover.php页面中,用户面临错误。下面列出了错误

Warning: mysql_query() [function.mysql-query]: Access denied for user 'crimst1d'@'localhost' (using password: NO) in /home/crimst1d/public_html/recover.php on line 19

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/crimst1d/public_html/recover.php on line 19
这里我的站点无法连接到MySQL数据库。如何连接

下面是我对recover.php页面的配置

<?
/**********************************************************************************************************************************************
    ScriptBux Version 2.50 beta
    This Script has been created and coded by Gabrola and edited by hassan ahmady.
    If you find any bugs in the script report at support@thealternatif.info or contact hassan ahmady.
    Copywrite ScriptBux 2008;
    Please make donations if you use this sript for commercial use
    to My paypal account "bisnis-usd@plasa.com"
************************************************************************************************************************************************/

?>

<h3>Forgot Password</h3>
<?php
if($_POST)
{
  $code = $_POST["code"];
  $email = $_POST["email"];
  $emailx = mysql_query("SELECT COUNT(*) AS cnt FROM tb_users WHERE email='{$_POST['email']}'");
  $emailx = mysql_fetch_array($emailx);
  $emailx = $emailx["cnt"];
  $errormsg = false;
  if($_SESSION['string'] != $code)
  {
    $error = 1;
    $errormsg .= "<b>Error -</b> The captcha was entered incorrectly.<br />";
  }
  if(!$code)
  {
    $error = 1;
    $errormsg .= "<b>Error -</b> The captcha was entered incorrectly.<br />";
  }
  if(!$email)
  {
    $error = 1;
    $errormsg .= "<b>Error -</b> The email was not supplied.<br />";
  }
  if(!$emailx)
  {
    $error = 1;
    $errormsg .= "<b>Error -</b> No account was found with that email address.<br />";
  }
  if($_SESSION['next_reseptsend'] != 0)
  {
    $error = 1;
    $errormsg .= "<b>Error -</b> You have already made a password retrieval within the last 15 minutes.<br />";
  }
  $_SESSION['string'] = false;
  if($error)
  {
    print $errormsg."<br><br>";
  } else {
    $s = mysql_query("SELECT * FROM tb_users WHERE email='{$_POST['email']}'");
    $x = mysql_fetch_array($s);
    $_SESSION['next_reseptsend'] = 1;
    $message = "Hello {$x['username']},
    You requested to resend your account password a while ago.

    Account Username: {$x['username']}
    Account Password: {$x['password']}

    We hope you can have a good time earning your money again,

    Thanks,
    {$config['site_name']}";
    mail($x["email"],"Password Retrieval - ".$config["site_name"],$message,"From: mail@".$_SERVER['HTTP_HOST']);
    print "<b>Password Sent!</b><br />
    We have dispatched your password to your email address.<br />
    You can only make another account retrieval again in 15 minutes.<br />";
  }
}
?>

<div style="padding-left:25px;">
<form action="recover.php" method="post" name="resend">
<table>
<tr><td class="midtext">Your Email:</td><td><input type="text" name="email" size="25" class="form" autocomplete="off" value="<?=$_POST['email']?>"></td></tr>
<tr><td class="midtext" valign="top">Security Code:</td><td class="midtext"><img src="image.php" onclick="this.src='image.php?newtime=' + (new Date()).getTime();"><br /><span style="font-size:10px;">(Click to reload)</span><br /><input type="text" name="code" size="17" maxlength="" autocomplete="off" class="form"></td></tr>
<tr><td></td><td align="right"><input type="submit" value="Login" name="loginsubmit"  class="inputbox"></td></tr>
</table>
</form>
</div>

<?php

?>

您需要向数据库中添加一个用户,以及一个脚本可以通过和连接到的数据库

将以下内容放在脚本顶部:

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database name');

以下是如何解决您的安全漏洞。更改此项:

$emailx = mysql_query("SELECT COUNT(*) AS cnt FROM tb_users WHERE email='{$_POST['email']}'");
为此:

$emailUntainted = mysql_real_escape_string($_POST['email']);
$emailx = mysql_query("
    SELECT COUNT(*) AS cnt
    FROM tb_users
    WHERE email='{$emailUntainted}'
");
你有两个问题需要解决;也要读一些书,了解为什么这是必要的:


后脚本:正如@Esailija所说,使用PDO和准备好的语句更好,但这需要您进行更多的学习。快速修复此问题,然后尽可能切换到PDO。

我只想要可以解决我问题的可接受答案。请提供帮助。您在哪里连接到数据库?请停止使用古老的mysql_*函数编写新代码。它们不再得到维护,社区已开始恢复。相反,你应该学习并使用或。若你们不能决定,文章将帮助你们选择。如果你愿意学习,这是一个很好的PDO相关教程。如果我是你,我不会为这个脚本付费——你的第一个mysql_查询有一个SQL注入漏洞。编辑:如果您不是该脚本的作者,请与他们联系,并告知他们他们的工作不安全。请在第19行的recover.php中显示代码。您正在连接到数据库,并且还包括连接代码;mysql_select_dbmydb;在mysql之前,有些人提出了一个查询,但似乎什么都没有改变。请帮忙。我只有一个mysql数据库和一个用户。我需要为这个再做一个吗?如果是,那么我应该创建一个用户或数据库还是同时创建两个?保存并重新加载@早上好,是的。但一切似乎都没有改变。请帮助我。您的数据库是否有相应的表?再次解释您看到的错误。好的。你说过我有两个要修的。这是另一个$s=mysql\u querySELECT*来自tb\u用户,其中email='{$\u POST['email']}'?是的,没错。因此,用同样的方法将“{$_POST['email']}”替换为“{$emailUntainted}”。