Jump to content

Recommended Posts

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)) {

 

?>

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618005
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618100
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618101
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-618106
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/119964-just-debugging/#findComment-619002
Share on other sites

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.