2DWorlds Forums
A simple currency system - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: Off Topic (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=5)
+--- Forum: Programming (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=30)
+--- Thread: A simple currency system (/showthread.php?tid=8510)



A simple currency system - Mustachio - 10-27-2011

I am only giving the currency script, as I assume that you know how to use databases.

Currency Getter
Code:
<?php
include('conn.php');
session_start();
$sql=mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'");
$row=mysql_fetch_array($sql);
echo "You have <b>" . $row['money'] . "</b> cash!";
?>

Shop system
Code:
<?php
include('conn.php');
session_start();
$sql=mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'");
$row=mysql_fetch_array($sql);
if(isset($_POST['submit'])){
if($row['money'] >= $_POST['price']){
mysql_query("UPDATE users SET money = money-$_POST['price'] WHERE username = '$_SESSION[username]'");
}
else{
echo "You lack sufficient funds";
}
?>



RE: A simple currency system - noob007 - 10-27-2011

SANITIZE YOUR QUERIES PLOX


RE: A simple currency system - Mustachio - 10-27-2011

(10-27-2011, 07:02 PM)noob007 Wrote: SANITIZE YOUR QUERIES PLOX

NO U
I REFUSE TO USE RESULT AS IT MAKES TEH SCRIPT LONGER WHICH TAKES UP MOAR SPACE


RE: A simple currency system - Jacob__mybb_import1 - 10-27-2011

[Image: exploits_of_a_mom.png]


RE: A simple currency system - Mustachio - 10-27-2011

There is no need to sanitize this code, which uses no inputs.


RE: A simple currency system - noob007 - 10-27-2011

Session variables are basically cookies, which can be modified by the client.