jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 i tried code, i get no errors but it also doesnt purchase the ticket.. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152370 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 Show me the result array. With print_r. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152371 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 "Insufficent balance. Please add more ISK" thats from the print_r command. There is enough "isk".. if i remove your code i can purchase a ticket as i have enough isk... Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152380 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 What does the sql query return as a result? What does print_r($balArray); give you? Could you show me a bit of your current code too? Helps debugging. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152384 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 ok i can now purchase a ticket (typo, prob my fault.) i am limited to 1 ticket per user - Great! but the check for tickets bought in last 24 doesnt work! i can still purchase a ticket although there are no tickets bought in last 24 hours. the print_r command just says "Insufficent balance. Please add more ISK" Current code; <?php session_start(); //header('Location: index.php'); include "connect.php"; $id = $_SESSION['id']; $user = $_SESSION['user']; $ticketNumber = $_POST[ticketNumber]; //echo $_POST[ticketNumber]; $today = date("Ymd G:i:s"); $querySold = mysql_query("SELECT * FROM tickets WHERE promoID='$_POST[promoID]' AND (ticketNumber='$ticketNumber' OR username = '$user');") or die(mysql_error()); //echo $querySold; $sold = mysql_fetch_assoc($querySold); //print_r($sold); //echo $sold; //check if ticket is sold if(empty($sold)!=FALSE){ $queryBal = mysql_query("SELECT t1.username, t2.user_iskbalance AS balance FROM tickets AS t1 LEFT JOIN users AS t2 ON t1.username = t2.username WHERE t1.username = '$user' AND HOUR(TIMEDIFF(NOW(), t1.purchaseDate)) > 24;") or die(mysql_error()); $balArray = mysql_fetch_assoc($queryBal); //print_r($balArray); if(count($balArray) > 0) { // User has bought a ticket last 24 hour, // Get balance $bal = $balArray[balance]; } else { die("You haven't bought a ticket in the past 24 hours"); } //check if he has the money to buy the ticket if($bal>=$_POST[ticketPrice]){ $newBal = $bal-$_POST[ticketPrice]; //remove the money $queryBalRemoveal = mysql_query("UPDATE `users` SET `user_iskbalance`='$newBal' WHERE `username`='$user';") or die(mysql_error()); //buy ticket $query = mysql_query("INSERT INTO tickets(promoID, username, charID, ticketNumber, ticketPrice, purchaseDate) VALUES ('$_POST[promoID]', '$user', '$id', '$_POST[ticketNumber]', '$_POST[ticketPrice]', '$today');") or die(mysql_error()); } else{ die("Insufficent balance. Please add more ISK") ; } } else{ die("Ticket has been Sold or you are not allowed to purchase more than 1 ticket for this auction."); } ?> Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152391 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 Woopdy: (), t1.purchaseDate)) > 24; should be less than ( < 24) =) Hope that solves the problem... Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152393 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 so did i. didnt work.. =( Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152397 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 What seems to be the problem? Please give me some examples of print_r($balArray); Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152399 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 for some reason print_r isnt outputting much... but i guess it has something to do with the timediff code. if i change it to "<" it wont post any tickets. and if i change it to ">" it allows me to buy even though i havnt bought a ticket in 24 hours. thanks for you're hlp upto now though bro. appreciate it. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152405 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 Well, print_r should only output username and balance if and only if the user has bought a ticket in the past 24hours. If he hasn't the array should be empty, because he isn't allowed to buy promo ticket then. Do you get row out of the query tough? And when don't you get a row? Do you have the balance when you get a row? Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152407 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 when i buy a ticket i get the following: Array ( [username] => USER [balance] => 1699989 ) ticket price is set to 1 fyi. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152411 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 That's weird. Then it should work. The array should be empty if no tickets have been bought in the last 24 hours. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152464 Share on other sites More sharing options...
jacko_162 Posted December 29, 2010 Author Share Posted December 29, 2010 That's weird. Then it should work. The array should be empty if no tickets have been bought in the last 24 hours. fixed it bro. =) thanks for all the help though. *thumbsup* Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152580 Share on other sites More sharing options...
johnny86 Posted December 29, 2010 Share Posted December 29, 2010 Do you mind sharing the solution with us? =) So that others who look into this thread might get a solution to their problem. Link to comment https://forums.phpfreaks.com/topic/222817-if-statment-help/page/2/#findComment-1152595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.