Jump to content

if statment help


jacko_162

Recommended Posts

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.");	
}
?>

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

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?

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.