boblee Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/ Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 $result = mysql_query($query,$conn); You had them the wrong way round. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722166 Share on other sites More sharing options...
boblee Posted December 23, 2008 Author Share Posted December 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722376 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 You had them the right way. even though your naming seems to be alittle off you named your connectino $queru and your query $conn lol. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722381 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722385 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722390 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 Chances are your post variable isn't coming over. Nail on the head. $_post should be $_POST =) Since PhP Is CasE SenSiTiVe =) Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722394 Share on other sites More sharing options...
boblee Posted December 23, 2008 Author Share Posted December 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722399 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 And the echo produced what? Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722404 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 Change this: $result = mysql_query($query); To: $result = mysql_query($query) or die(mysql_error()); And see if it is erroring out. Also see the $_POST issue 3 above this one if you have not already. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722406 Share on other sites More sharing options...
boblee Posted December 23, 2008 Author Share Posted December 23, 2008 okay, did that and it spit out: Unknown column 'company' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722413 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 Error is clear, you have no column named company. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722415 Share on other sites More sharing options...
premiso Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722418 Share on other sites More sharing options...
boblee Posted December 23, 2008 Author Share Posted December 23, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722420 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 use IF $submit clause and if it's true, do what you want, if false, do something else. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722429 Share on other sites More sharing options...
boblee Posted December 23, 2008 Author Share Posted December 23, 2008 will i need to get rid of the action='login2.php'? Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722440 Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 Is login2.php the page you want to go to? Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722443 Share on other sites More sharing options...
boblee Posted December 24, 2008 Author Share Posted December 24, 2008 its the name of the file I'm currently working on Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722909 Share on other sites More sharing options...
trq Posted December 24, 2008 Share Posted December 24, 2008 boblee, can you please use or tags when posting code? I've edited all your posts. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722918 Share on other sites More sharing options...
revraz Posted December 24, 2008 Share Posted December 24, 2008 That really doesn't answer the question. its the name of the file I'm currently working on Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722928 Share on other sites More sharing options...
boblee Posted December 24, 2008 Author Share Posted December 24, 2008 sorry, I should have been clearer. Its not the file I want to goto its the one I'm already on. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-722964 Share on other sites More sharing options...
revraz Posted December 24, 2008 Share Posted December 24, 2008 When you use a FORM, the ACTION is where you want to go to after you hit SUBMIT. Quote Link to comment https://forums.phpfreaks.com/topic/138151-supplied-argument-is-not-a-valid-mysql/#findComment-723149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.