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
Edited by Zane
Link to comment
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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.