Need some PHP SQL help please!
I have been staring at this crap hour 2 hours now, and I've finally narrowed the problem down to this code.
What I want to happen: The BIDS database is checked to see if there's a row where the user_id is equal to $userID AND auction_ID = $auctionID. If there is no such combination in the BIDS table, set that $listBidder to a string so we can insert that value later. If the the combination IS found, set $listBidder so we can update that row in the table later.
What actually happens: (mysql_num_rows($rowCheck)) ALWAYS returns 0 (I think), so I always hit the INSERT INTO version of $listBidder.
The code listed below are the ONLY instances of $listBidder in the code right now that aren't commented out, so I am sure the problem exists here somewhere.
I have been staring at this crap hour 2 hours now, and I've finally narrowed the problem down to this code.
What I want to happen: The BIDS database is checked to see if there's a row where the user_id is equal to $userID AND auction_ID = $auctionID. If there is no such combination in the BIDS table, set that $listBidder to a string so we can insert that value later. If the the combination IS found, set $listBidder so we can update that row in the table later.
What actually happens: (mysql_num_rows($rowCheck)) ALWAYS returns 0 (I think), so I always hit the INSERT INTO version of $listBidder.
The code listed below are the ONLY instances of $listBidder in the code right now that aren't commented out, so I am sure the problem exists here somewhere.
Code:
$bidsCheck = mysql_query("SELECT * FROM BIDS WHERE (user_id='$userID' AND auction_id='$auctionID')");
$rowCheck = mysql_fetch_array($bidsCheck);
if(mysql_num_rows($rowCheck) == 0)
{
$listBidder = "INSERT INTO BIDS (user_id,auction_id,amount)VALUES ('{$userID}','{$auctionID}','{$bidPrice}')";//First bid for user
}
else
{
$listBidder = "UPDATE BIDS SET amount='$bidPrice' WHERE (auction_id='$auctionID' AND user_id='$userID')";//Second bid for user and beyond
}