Jump to content

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, did that and it spit out:

Unknown column 'company' in 'where clause'

 

Looks like you need to make sure you have a column called "company" in your database table. If not you need to find out what the name should be.

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>



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.