inquisitive Posted August 16, 2008 Share Posted August 16, 2008 Here is the code... for some reason it is erroring and here is the error: Warning: mysql_fetch_array(): 4 is not a valid MySQL result resource in /home/content/c/a/l/calvinsolar/html/admin/accounts.php on line 65 The error is for the WHILE STATEMENT...any help would be awesome <?php { if(isset($_POST['mysubmit'])) if($_POST['type_account'] == 'pr_specialist') {$query = 'SELECT * FROM users WHERE pending = 0'; $query = ' SELECT * From users Where type = "PRSpecialist"'; $result = mysql_query($query) or die(mysql_error());} elseif($_POST['type_account'] == 'students') {$query = 'SELECT * FROM users WHERE pending = 0'; $query = ' SELECT * From users Where type = "Student"'; $result = mysql_query($query) or die(mysql_error());} elseif($_POST['type_account'] == 'contractors') {$query = 'SELECT * FROM users WHERE pending = 0'; $query = ' SELECT * From users Where type = "Contractor"'; $result = mysql_query($query) or die(mysql_error());} elseif($_POST['type_account'] == 'none') {$query = 'SELECT * FROM users WHERE pending = 0'; $query = ' SELECT * From users Where type = "PRSpecialist"'; $result = mysql_query($query) or die(mysql_error());} } while ($line = mysql_fetch_arrayphp($result, MYSQL_ASSOC)) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/ Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 Do echo $query; to see if it makes sense. (are you aware that you're overwriting first "SELECT WHERE pending = 0" with "SELECT WHERE type='type'" ?) Try also print_r($result); to see what's in it. You might also want to change this if-elseif-elseif... construction to <?php switch($_POST['type_account']) { case "pr_specialist": $type = "PRSpecialist"; break; case "students": $type = "Student"; break; /* more */ } $query = "SELECT * FROM users WHERE pending = 0 AND type = '$type'"; $result = mysql_query($query) or die(mysql_error()); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { /* parse rows */ } ?> Last but not least: are you using mysql or mssql (you're posting in mssql forum, but using mysql functions). I assumed you're using mysql. Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618005 Share on other sites More sharing options...
inquisitive Posted August 16, 2008 Author Share Posted August 16, 2008 I didn't see where you declared the type variable.... Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618090 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 It's not decalred, as no declarations are needed in PHP. But for completness sake you can put $type = NULL; above the code I've written before. <?php $type = NULL; switch($_POST['type_account']) { /*...*/ What's important, is that $type gets its value within switch statement, based on $_POST['type_account'] value <?php /*this example is slightly different than the last one*/ switch($_POST['type_account']) { case "pr_specialist": //if $_POST['type_account'] is equal to "pr_specialist" case "none": //or it is equal to "none" $type = "PRSpecialist"; //$type gets value "PRSpecialist" break; case "students": $type = "Student"; break; case "contractors": $type = "Contractor"; break; default: //this section is executed only if none of the sections above are die("No account type selected, or account type invalid"); } Once the $type has proper value you may use it in your query. Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618100 Share on other sites More sharing options...
inquisitive Posted August 16, 2008 Author Share Posted August 16, 2008 doesnt really work at all... I'm working with a list to select the account type that I want to view...and this code just ties this select button with the database to display the info I am looking for...the switch and case statement didn't seem to work very well....not sure why...but this method was working before...it worked for about 5presses of the submit button then it just crashed... Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618101 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 It crashed, but did it give any warning/error? switch/case gets some time to get used to, and perhaps you shouldn't use it right now, if you feel more comfortable with if-else. Your main problem was with getting results from database. Did you succeed at that? <?php $query = 'SELECT * FROM users WHERE pending = 0'; $query = ' SELECT * From users Where type = "PRSpecialist"'; That's part of your code. As you can see, you're assigning diffirent values to one variable. At the end of this code $query holds only SELECT * From users Where type = "PRSpecialist" If you wanted to have two queries on one variable you should do it this way: <?php $query = 'SELECT * FROM users WHERE pending = 0'; $query .= ' SELECT * From users Where type = "PRSpecialist"'; So at the end $query would hold: SELECT * FROM users WHERE pending = 0 SELECT * From users Where type = "PRSpecialist" However mysql_query() does not support multiple queries so it wouldn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618106 Share on other sites More sharing options...
inquisitive Posted August 18, 2008 Author Share Posted August 18, 2008 This is the error that my code is returning...it doesn't like this statement: (statement inside the asteriks) ****while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {******* Warning: mysql_fetch_array(): 7 is not a valid MySQL result resource in /home/content/c/a/l/calvinsolar/html/admin/accounts.php on line 60 Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-619002 Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 This means, that for some reason query results weren't stored in $result variable. You should check if your query returns any rows. Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-619019 Share on other sites More sharing options...
inquisitive Posted August 18, 2008 Author Share Posted August 18, 2008 thats the thing...it returns one result...and then errors...its sooo strange Quote Link to comment https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-619021 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.