Jump to content

Multiple Conditions Problem


tekrscom

Recommended Posts

MySQL 5.0.32

 

Hi everyone... It's been a while...

 

But anyway, I am having problems with a multiple condition query... It keeps giving me an error... "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource"

 

The query is as follows...

 

$query = mysql_query("SELECT EndClients.EndClientBusinessName, Quotes.QuoteID, Quotes.QuoteTitle FROM Quotes LEFT JOIN EndClients ON Quotes.EndClientID = EndClients.EndClientID WHERE Quotes.QuoteID = '$_GET[quoteid]' AND Quotes.ITCompanyID = '$_SESSION[userID]' AND Quotes.QuoteStatus = 'Generation'") or die(mysql_error());

 

I know, you're probably wondering why I would be adding more conditions after already defining the ID of the row in which I am wanting,... it's merely added protection to ensure the right person is making the query and also that they're not trying to pull a row maliciously that is no longer in 'Generation' status...

 

The whole code is as follows:

<?
session_start();
if ($_SESSION['Condition'] !== 'Logged' || $_SESSION['UserType'] !== 'ITCo') {
    header("Location: login.php");
}
else {
    include_once "connection.php";
    include_once "emailnotification.php";
    $query = mysql_query("SELECT EndClients.EndClientBusinessName, Quotes.QuoteID, Quotes.QuoteTitle FROM Quotes LEFT JOIN EndClients ON Quotes.EndClientID = EndClients.EndClientID WHERE Quotes.QuoteID = '$_GET[quoteid]' AND Quotes.ITCompanyID = '$_SESSION[userID]' AND Quotes.QuoteStatus = 'Generation'") or die(mysql_error());
    while ($row = mysql_fetch_assoc($query)) {
        $TheCurrentDate = date("Y-m-d");
        $query = mysql_query("UPDATE Quotes SET QuoteDate = '$TheCurrentDate', QuoteStatus = 'Pending Admin Approval' WHERE QuoteID = '$row[QuoteID]'");
        ITCoSubmittedQuote_EmailAdmin($_SESSION['UserName'], $row['EndClientBusinessName'], $row['QuoteTitle']);
        header("itcoclientquotes.php?function=continueincompletequote&status=quotesubmitted");
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/192828-multiple-conditions-problem/
Share on other sites

Your code inside of your while() {} loop is reusing the $query variable, so when the while loop condition is evaluated after the first UPDATE query is executed you get an error because $query no longer contains the result resource from the first query.

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.