Jump to content

supplied argument is not a valid MySQL


boblee

Recommended Posts

Hey all, having some more troubles.

I'm getting this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/J/a/p/JapII/html/reftek/login2.php on line 26
and I'm not too sure how to fix it, been messing with it for quite some time now.

 

here are lines 23-29

	           echo  "<form method='post' action='account.php'>";
               $conn ="SELECT product_id FROM `customers_products` WHERE company =  '".mysql_real_escape_string($_post['company'])."'";
Line 26--> $result = mysql_query($conn,$query);       
               while($row=mysql_fetch_row($result))
                 {
                   $product_id[] = $row[0];
                 }

 

 

and the entire thing:

<?php
  session_start(); 
$query = mysql_connect("****************.net", "*********", "**********") or die(mysql_error());
mysql_select_db('********', $query) or die(mysql_error());
  
if(isset($_GET['try'])) {
  
     If(empty($_POST['company']) OR empty($_POST['password'])) {
         echo 'Please fill in all the required fields!';
     }
     else {
         $company = addslashes($_POST['company']);
         $password = md5($_POST['password']);
         $queryA = mysql_query("SELECT usergroup FROM users WHERE company = '" . $company . "' AND password = '" . $password . "'") or die(mysql_error());
         
        
         list($usergroup) = mysql_fetch_row($queryA);
  
         if(empty($usergroup)) {
            echo 'No combination of username and password found.';
         }
         else{
           echo  "<form method='post' action='account.php'>";
               $conn ="SELECT product_id FROM `customers_products` WHERE company =  '".mysql_real_escape_string($_post['company'])."'";
               $result = mysql_query($conn,$query);
               while($row=mysql_fetch_row($result))
                 {
                   $product_id[] = $row[0];
                 }
               echo  "<select name='product'>\n" ;
               foreach( $product_id as $v  )
                {
                 echo "<option value='$v'>\n" .$v."</option>\n";
                }
               echo "</select>\n";
               
               echo  "<input type='submit' name='submit' value='Go' />";
               echo  "</form>\n";
               
               
               if(isset($_POST['product'])) {
                $product = ($_POST['company']);

                $firm ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_post['product'])."' AND type = 'frimware'";
                $result = mysql_query($conn,$query);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $z  )
                           {
                              echo "<li> <a href='support/$product/firmware/$z'>\n" .$z."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $soft ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_post['product'])."' AND type = 'software'";
                $result = mysql_query($conn,$query);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $y  )
                           {
                             echo "<li> <a href='support/$product/software/$y'>\n" .$y."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $doc =="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_post['product'])."' AND type = 'doc'";
                $result = mysql_query($conn,$query);
                while($row=mysql_fetch_row($result))
                    {
                     $name[] = $row[0];
                    }
                    echo "<ul>\n";
                   foreach( $name as $x  )
                          {
                            echo "<li> <a href='support/$product/doc/$x'>\n" .$x."</a></li>\n";
                          }
                   echo "</ul>\n";
                   echo "<br />";
}
        }      
    
     }
  
}
?>
<form action="login2.php?try=true" method="post">
     Username: <input type="text" name="company"><br>
     <br>
     Password: <input type="password" name="password"><br>
     <br>
    <input type="submit" value="Login">
  </form>
<a href="logout.php">Log Out</a>

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/
Share on other sites

When I do that I get two errors:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/J/a/p/JapII/html/reftek/login2.php on line 25

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/J/a/p/JapII/html/reftek/login2.php on line 26

For mysql, don't use the $conn. It is not necessary unless you are using mysqli.

 

But, if you want to know the real error

 

$query = mysql_connect("****************.net", "*********", "**********") or die(mysql_error());

 

Should be

 

$conn = mysql_connect("****************.net", "*********", "**********") or die(mysql_error());

 

Then also change this:

               $conn ="SELECT product_id FROM `customers_products` WHERE company =  '".mysql_real_escape_string($_post['company'])."'";
Line 26--> $result = mysql_query($conn,$query);  

 

To

               $query ="SELECT product_id FROM `customers_products` WHERE company =  '".mysql_real_escape_string($_POST['company'])."'";
Line 26--> $result = mysql_query($query,$conn); // or remove the ,$conn  

 

You didn't have it wrong, you just named them strange ($conn is usually connection, $query is usually a query).

 

In order to trouleshoot this, you need to do two things.

 

$conn ="SELECT product_id FROM `customers_products` WHERE company =  '".mysql_real_escape_string($_post['company'])."'";

              $result = mysql_query($conn);

 

 

Echo $conn to see what it contains, use mysql_error() after the query to see if there are errors.  Chances are your post variable isn't coming over.

Okay, I swiched those around but I'm still getting this error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/J/a/p/JapII/html/reftek/login2.php on line 26

 

Edit: just read last 3 posts giving the echo thing a go.

Okay I feel dumb its supposed to be customer. *face palm* -Thanks for all your guys help.

 

Edit:

Well I have another question, with the same file, I know this is the problem:

echo  "<form method='post' action='login2.php'>";

of course action="login2.php" just starts the whole thing from the top again, so how do I go about getting it to execute the code underneath it?:


               if(isset($_POST['product'])) {
                $product = ($_POST['company']);

                $firm ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'frimware'";
                $result = mysql_query($firm,$conn);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $z  )
                           {
                              echo "<li> <a href='support/$product/firmware/$z'>\n" .$z."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $soft ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'software'";
                $result = mysql_query($soft,$conn);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $y  )
                           {
                             echo "<li> <a href='support/$product/software/$y'>\n" .$y."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $doc =="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'doc'";
                $result = mysql_query($doc,$conn);
                while($row=mysql_fetch_row($result))
                    {
                     $name[] = $row[0];
                    }
                    echo "<ul>\n";
                   foreach( $name as $x  )
                          {
                            echo "<li> <a href='support/$product/doc/$x'>\n" .$x."</a></li>\n";
                          }
                   echo "</ul>\n";
                   echo "<br />";
}
        }      
    
     }
  
}
?>

Entire thing:

<?php
  session_start(); 
$conn = mysql_connect("****************.net", "*********", "*********") or die(mysql_error());
mysql_select_db('*********', $conn) or die(mysql_error());
  
if(isset($_GET['try'])) {
  
     If(empty($_POST['company']) OR empty($_POST['password'])) {
         echo 'Please fill in all the required fields!';
     }
     else {
         $company = addslashes($_POST['company']);
         $password = md5($_POST['password']);
         $queryA = mysql_query("SELECT usergroup FROM users WHERE company = '" . $company . "' AND password = '" . $password . "'") or die(mysql_error());
         
        
         list($usergroup) = mysql_fetch_row($queryA);
  
         if(empty($usergroup)) {
            echo 'No combination of username and password found.';
         }
         else{
           echo  "<form method='post' action='login2.php'>";
               $query ="SELECT product_id FROM `customers_products` WHERE customer =  '".mysql_real_escape_string($_POST['company'])."'";
               $result = mysql_query($query,$conn) or die(mysql_error());
               while($row=mysql_fetch_row($result))
                 {
                   $product_id[] = $row[0];
                 }
               echo  "<select name='product'>\n" ;
               foreach( $product_id as $v  )
                {
                 echo "<option value='$v'>\n" .$v."</option>\n";
                }
               echo "</select>\n";
               
               echo  "<input type='submit' name='submit' value='Go' />";
               echo  "</form>\n";
               
               
               if(isset($_POST['product'])) {
                $product = ($_POST['company']);

                $firm ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'frimware'";
                $result = mysql_query($firm,$conn);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $z  )
                           {
                              echo "<li> <a href='support/$product/firmware/$z'>\n" .$z."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $soft ="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'software'";
                $result = mysql_query($soft,$conn);
                while($row=mysql_fetch_row($result))
                         {
                          $name[] = $row[0];
                         }
                    echo "<ul>\n";
                    foreach( $name as $y  )
                           {
                             echo "<li> <a href='support/$product/software/$y'>\n" .$y."</a></li>\n";
                           }
                    echo "</ul>\n";
                    echo "<br />";
         
                $doc =="SELECT name FROM `product_docs_support` WHERE product_id =  '".mysql_real_escape_string($_POST['product'])."' AND type = 'doc'";
                $result = mysql_query($doc,$conn);
                while($row=mysql_fetch_row($result))
                    {
                     $name[] = $row[0];
                    }
                    echo "<ul>\n";
                   foreach( $name as $x  )
                          {
                            echo "<li> <a href='support/$product/doc/$x'>\n" .$x."</a></li>\n";
                          }
                   echo "</ul>\n";
                   echo "<br />";
}
        }      
    
     }
  
}
?>
<form action="login2.php?try=true" method="post">
     Username: <input type="text" name="company"><br>
     <br>
     Password: <input type="password" name="password"><br>
     <br>
    <input type="submit" value="Login">
  </form>
<a href="logout.php">Log Out</a>



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.