Hello, I have had this error for a long time and tried everything that I know to fix that, but unfortunately I was unsuccessful.

Error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/XXX/public_html/xxx/profile.php on line 800

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxx/public_html/xxx/profile.php on line 801

I am doing a pagination in profile.php for my website. This is the PHP code I have for it.

    <?php
$query ="SELECT * FROM x1 ORDER BY x2 ASC LIMIT 7";
$result = mysqli_query($sql,$query);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$msg_id=$row['id'];
$message=$row['x2'];
?>
<?php

if(isset($_POST['lastmsg']) &&is_numeric($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$query="SELECT * FROM x1 where id>'$lastmsg' order by x2 asc limit 7";
$result = mysqli_query($sql,$query);


while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{ 
$msg_id=$row['id'];
$message=$row['x2'];
?>

BTW. I have a code that connects to database on the same page.

    You should be checking to see if [man]mysqli_query/man returns boolean FALSE (indicating an error has occurred) and, if so, outputting or logging (whichever is appropriate) the MySQL error message (see [man]mysqli_error/man) and perhaps the query string itself as it was sent to the SQL server (helps to debug it if you can see it).

      I'll sound like a noob but how do I do that? You talk like a pro 😃 - Thanks for the reply anyway.

        The first error message says that the alleged database connection isn't one after all. And of course if that fails and the problem isn't dealt with, the next error is inevitable. So start by concentrating on fixing the first error first and then see how things go from there.

        But what really impresses me is that the code uses mysqli_query(), etc., and yet the error messages refer to mysql_query(), etc...

          @
          I don't know how this could help me though. Is there any specific steps that I should do to fix my error? Is it a common error?

          Thanks for your reply.

            xNeOx;10990502 wrote:

            Is there any specific steps that I should do to fix my error?

            Yup, two things:

            1. Show us the right source code. As Weedpacket points out, the error message doesn't match up with any of the code you posted.

            2. Read through my post again and try to implement the changes I suggested.

              All you'd be doing is checking to see if a value is false, and if it is then output the string returned by a function. In other words, it's a simple if() statement.

              bradgrafelman;10990503 wrote:

              Yup, two things:

              1. Show us the right source code. As Weedpacket points out, the error message doesn't match up with any of the code you posted.

                I have no idea what I was thinking while posting the thread. Sorry for my mistake.

                This is the error:

                Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/XXX/public_html/xxx/profile.php on line 781
                
                Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/XXX/public_html/xxx/profile.php on line 782

                This is where the error is:

                    <?php
                $query = "SELECT * FROM x1 ORDER BY x2 ASC LIMIT 7";
                $result = mysqli_query($sql,$query);
                while($row = mysqlo_fetch_array($result,MYSQLI_ASSOC))
                {
                $msg_id=$row['id'];
                $message=$row['x2'];
                ?>

                Where is $sql defined?

                EDIT: And again, the second error message doesn't reflect the code snippet (which uses a function called mysqlo_fetch_array/b, not [man]mysqli_fetch_array/man).

                Are you not copying-and-pasting the error messages and source code directly into your posts?

                  Write a Reply...