0

I try to upload php file with my site to get data from form,its running perfect but its shows error when its live.

The Error is: Warning: mysqli_connect(): (HY000/1044): Access denied for user 'ideamak1_sagar'@'%' to database 'ideamak1_data' in /home/ideamak1/public_html/afterform.php on line 12 ERROR: Could not connect gh.

Here's my php code

<!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>
Sagar Parikh
  • 288
  • 5
  • 20
  • 2
    you're still trying to connect to 'localhost', that might be a bit of a stretch... – lovelace Jun 21 '18 at 22:19
  • please read https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question – lovelace Jun 21 '18 at 22:21
  • And also read [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1), especially since its live.. – Lawrence Cherone Jun 21 '18 at 22:24
  • @lovelace not necessarily... Most servers are connected to mysql on their `localhost`. – Sam Jun 21 '18 at 22:31
  • 3
    User permission... 1 of two things, 1. mysql user doesn't exist on the server; 2. the user does not have access to the `ideamak1_data` database. – Sam Jun 21 '18 at 22:33
  • sorry, my bad,I remove the photo – Sagar Parikh Jun 22 '18 at 03:57
  • @Samuel 1.I create that username so 2.why its does not have access! – Sagar Parikh Jun 22 '18 at 03:59
  • @SagarParikhSGR did you give the username access of the database? It needs the right permissions. – Sam Jun 22 '18 at 04:00
  • @Samuel as I know I have to create a database, create user & generate a password to accessing the database, I did these things, I can send you a photo of that if you need. – Sagar Parikh Jun 22 '18 at 05:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173596/discussion-between-sagar-parikh-sgr-and-samuel). – Sagar Parikh Jun 22 '18 at 05:53

2 Answers2

1

error_reporting(E_ERROR | E_PARSE);

Put that at the top of your PHP and it will stop showing error messages. This does not fix your error. But it sounds like you just want to have a nice display.

L1R
  • 215
  • 2
  • 9
1
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Faran
  • 138
  • 6
  • 2
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Suraj Rao Oct 27 '21 at 11:01