FuZzI Posted November 20, 2007 Share Posted November 20, 2007 Hello, I'm having a small problem here. I've mounted a script that enables members to click on a Buy button and it will take off $750,000 from their account and send them to a URL to download the file. Now, I'm still wondering whats the script to tell members when they don't have enough money, that they can't buy it and it will cancel sending them to the URL. Here is the PHP code for the Buy button: <?PHP $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method=\"post\"><a href="http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"><input type=submit name=buy value=Buy!></a></form> <?PHP mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); ?> I was thinking of adding the below script on top of it, but it doesn't work .. if ($geld < 750000) { $melding = "You don't have enough money."; Really need the help, much appreciated. Thanks, FuZzI Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 20, 2007 Share Posted November 20, 2007 do some select statement that will search if the users money is enough something like [ code] $q='select * from table where theidofuser=givenid'; $row = mysql_fetch_array(mysql_query($q)); if ($row['money'] < 700000){ //put some stuff here } else { let him go to the other page } Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Thanks for the quick reply my friend. I've also just noticed that everytime I visit the page, it automatically takes off $750,000 from my account even though I didn't press the Buy button. Do you know how to fix this? Thanks, FuZzI Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 validate your form submission - use isset to check and see if form has been submitted with $_POST. Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Which means ... Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 20, 2007 Share Posted November 20, 2007 <?PHP $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <a href="http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"> <input type='submit' name='buy' value='Buy!'></a> </form> <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); } ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 <?php if(isset($_POST['fieldnamehere'])) { // process code here } else { // do nothing } Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Thanks alot for your help so quickly, It's amazing! Well, now it doesn't take off money each time you visit the page, that's a fix! But, when I click on the buy button, it sends the URL link but it doesn't take off $750,000 from the account .. I'm using the code that teng84 showed above. Here's the code: <?PHP $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <a href="http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"> <input type='submit' name='buy' value='Buy!'></a> </form> <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 20, 2007 Share Posted November 20, 2007 $cookieusername check that variable if set see if it has a value ! Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Is this it? I have this in the file as well.. $lijstGebruikers = "SELECT * FROM users WHERE username='$cookieusername'"; Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 With the code on the first post it was taking off the $750,000. But now I know, it wasn't when I pressed the Buy! button, it was because I only visited the page. So ya, I need the script that will allow to take off the players money when the Buy! button is clicked. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 try this <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); header("Location: http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"); exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Almost there When I press the button, it takes away the money. Another problem fixed! But now... the download URL wrong pop-up. This is the error message: Warning: Cannot modify header information - headers already sent by (output started at /home/fuzzi/public_html/mafioso/_ip_block.php:23) in /home/fuzzi/public_html/mafioso/drug_org.php on line 56 Line 56 in drug_org.php reads: header("Location: http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"); Thanks for the help, need more help though FuZzI Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 take out the "20%" and replace with "/" and see if that helps Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Gives me the same error as above ... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 Ok this will work but its not too good a practice <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 That's perfect! Works like a charm. Thanks alot!! Now, If the member doesn't have enough money, it will tell him and cancel the URL. This is the final step ... I tried : <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; if ($row['geld'] < 700000){ } else { echo "You don't have enough money!"; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> But no luck .. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 if you do it like that; your going to run into the problem of whether or not client side javascript is enabled. if you do it like this, you better require you viewer have javascript enabled on their browsers. you could try to use an include like this: <?php if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); include("download_redirect.php"); } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; if ($row['geld'] < 700000){ } else { echo "You don't have enough money!"; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> download_redirect.php <?php header("Location: http://mafioso.ca/electronics/Mafioso/Drug/Organizer.rar"); exit; ?> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 you can try the following code but as phpQuestioner pointed out rightly about the javascript you'll have to keep a check on that <?PHP if (isset($_POST['buy']) && $row['geld'] >=750000){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } else if (isset($_POST['buy']) && $row['geld'] < 750000) { echo "You don't have enough money"; exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 Ok thanks for the heads up. I saw the script tag, that is javascript right? Now, the only thing I need is if the user hasn't got enough money, it will not send him to the URL and will say something like "You don't have enough money" Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 <?php if (isset($_POST['buy']) && $row['geld'] >=750000){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } else if (isset($_POST['buy']) && $row['geld'] < 750000) { echo "You don't have enough money"; header("refresh:10;url=notenoughmoney.php"); exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 rajivgonsalves, your script said I didn't have enough money even if I did. I changed it up a bit to this: <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } else if (isset($_POST['buy']) && $row['geld'] < 750000) { echo "You don't have enough money"; exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; ?> </center></td><!-- Col 1 --> <td> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> Everything works except for the 'not enough money' part. I tried buying it with only $1,500 and it accepted, it bring me to the download URL and my money went in the negative. Quote Link to comment Share on other sites More sharing options...
FuZzI Posted November 20, 2007 Author Share Posted November 20, 2007 phpQuestioner, your script said I didn't have enough money even though I did or not. Even showed an error message. Error Message Warning: Cannot modify header information - headers already sent by (output started at /home/fuzzi/public_html/mafioso/_ip_block.php:23) in /home/fuzzi/public_html/mafioso/drug_org.php on line 62 Line 62 header("refresh: 10;url=notenoughmoney.php"); Eumm.. I guess I can't use 'header' I'm sorry if this is getting complicated Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 assuming that the $row['geld'] was the current balance try this <?PHP if (isset($_POST['buy'])){ mysql_query("UPDATE `users` SET `geld`=`geld`-'750000' WHERE `username`='$cookieusername'"); echo '<script>location.href = "http://mafioso.ca/electronics/Mafioso%20Drug%20Organizer.rar"</script>'; exit; } $english_format_number = number_format($geld); echo "<b>You have:</b> $" . $english_format_number; echo "</center></td><!-- Col 1 --><td>"; if ($row['geld'] >= 750000) { ?> $750,000 <BR><BR> <form method="post"> <input type='submit' name='buy' value='Buy!'></a> </form> <? } else { echo "You do not have enough money"; } ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 20, 2007 Share Posted November 20, 2007 you would have to check you phpinfo() to see if headers are allowed or not in your version of PHP, but I do not see why they would not be. also, where are you checking to see if each person has $750,000 at; because I do not see you querying your database or some creditors database to check and see if each person has the amount or not. This is not in your code that you have provide us; so if you are checking for the specific amount somewhere else; you might want to take a look at that code for errors. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.