Jump to content

ima getting errors in queries


shazz

Recommended Posts

<?php
$con=mysqli_connect("localhost","my_user","","shazz");
$query = mysqli_query($con,"SELECT * from posts2 order by rand() LIMIT 0,4");
$post_title ="shazz";
while ($row=mysqli_fetch_array($query))
{
$post_id=$row['post_id'];
$post_title=$row['post_title'];
$post_date=$row['post_date'];
$post_author=$row['post_author'];
    $post_image=$row['post_image'];
    $post_keywords=$row['post_keywords'];
$post_content=substr($row['post_content'],0,200);
}


?>
 
the following are the errors im facing:
 
Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'shazz' inC:\xampp\htdocs\shazz\include\main_content.php on line 3

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given inC:\xampp\htdocs\shazz\include\main_content.php on line 4

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given inC:\xampp\htdocs\shazz\include\main_content.php on line 6
Link to comment
https://forums.phpfreaks.com/topic/295980-ima-getting-errors-in-queries/
Share on other sites

The error and the code that you posted don't match. The connection string for mysqli looks like this:

 

mysqli_connect("myhost","myuser","mypassw","mybd")

So the error Access denied for user ''@'localhost' to database 'shazz' meens that the "myuser" parameter is empty, not the "mypassw" as you show in your code. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.