【问题标题】:php file shows error on live serverphp 文件在实时服务器上显示错误
【发布时间】:2018-12-01 08:31:35
【问题描述】:

我尝试用我的网站上传 php 文件以从表单中获取数据,它运行完美,但在运行时显示错误。

错误是: 警告:mysqli_connect(): (HY000/1044): Access denied for user 'ideamak1_sagar'@'%' to database 'ideamak1_data' in /home/ideamak1/public_html/afterform.php 在第 12 行 错误:无法连接 gh。

这是我的 php 代码

<!DOCTYPE html>
<head>
</head>
<body>
  <?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $contact = $_POST['contact'];

  $comment = $_POST['comment'];

  $link = mysqli_connect("localhost", 
  "ideamak1_sagar", "Jmtm,?j4T(ZD", 
   "ideamak1_data") or die("ERROR: Could 
  not connect gh. ");
if(isset($_POST['name']) && 
  isset($_POST['email'])){
    $sql = "INSERT INTO user (name, email, 
 contact, comment) VALUES ('$name', 
 '$email', '$contact', '$comment')";
    $result = mysqli_query($link, $sql) or 
 die("ERROR: Could not connect. ");
    mysqli_close($link);
?>
    <h1>Thank You for Contacting Us <?php 
echo "<span 
style='color:purple;'>$name</span>"   ?> 
 </h1>

        <h3>We will be contacting you 
 soon</h3>      <a href="index.html">Click 
  here for redirecting site..</a

            <?php
    }else{
?>  <p>Your account have been not 
 registered yet.</p>
            <a href="index.html">Click here 
 for redirecting site..</a>
    <?php }?>
</body>
</html>

【问题讨论】:

标签: php mysql sql-server


【解决方案1】:

error_reporting(E_ERROR | E_PARSE);

将它放在 PHP 的顶部,它将停止显示错误消息。这不能解决您的错误。但听起来你只是想要一个漂亮的展示。

【讨论】:

  • 但是如果数据没有存储在数据库中,我认为文件本身没有必要
【解决方案2】:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

【讨论】:

  • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
猜你喜欢
  • 2017-02-27
  • 1970-01-01
  • 2015-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
  • 2013-03-08
  • 2012-07-29
相关资源
最近更新 更多