Jump to content

Could I Get Somone To Look Over My Code


Recommended Posts

In the script below it queries a database several times to login a user and change some of the fields in the users row. It logs the user in fine but doesn't seem to want to update the 'money' and 'experince' fields. So could someone just take a quick look over the code cause its probaly somthing I'm just missing now.

 

<?php
#Load Community Settings
require("comm/config.php");

$user1 = $_POST['user'];  #Username from login form
$pass1 = $_POST['pass'];  #Password from password form
$date = date('Ymd');    #Current Date
settype($date,"integer");

if (($user == NULL) OR ($pass == NULL)){
include("login.php");
print "<p align='center'><font face='" . $fface . "'>Invaild Username/Password</font></p>";
} else {
$db =mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($dbase,$db);
$sql = mysql_query("SELECT * FROM users WHERE username='$user1'",$db) or die(header("Location:login.php"));
if ($data = mysql_fetch_assoc($sql)) {
 	$password = $data['password'];
 	$username = $data['username'];
 	$jobs = explode("|",$data['jobs']);
 	$lastaccess = $data['last'];
 	settype($lastaccess, "integer");
}

if ($password == $pass1) {
 
 #Set Cookie For User In Community
 $comm = $username . "|" . $password;
 setcookie("comm",$comm);
 
 #Updates The User To Show He/She Is Online
 mysql_query("UPDATE users SET place='1',last='$date' WHERE username = '$user1'",$db);
 
 #Gives User His/Her Salary
 if ($lastaccess < $date){
 	$Sexp = 0;
 	$Smoney = 0;
 	$i = 0;
 	while($i < count($jobs)){
   $sql = mysql_query("SELECT salary FROM jobs WHERE title='$jobs[$i]'",$db) or die(mysql_error());
   if ($data = mysql_fetch_assoc($sql)){
   	$salary = explode("|",($data['salary']));
   	settype($salary,"integer");
   	
   	if ($salary[0] > $Smoney){
     $Smoney = settype($salary[0],"integer");
   	}
   	if ($salary[1] > $Sexp){
     $Sexp = settype($salary[1],"integer");
   	}
   }
   $i++;
 	}
 	$sql = mysql_query("SELECT money,experince FROM users WHERE username='$user1'",$db) or die(mysql_error());
 	if ($data = mysql_fetch_assoc($sql)){
   $CurrentMoney = $data['money'];
   $CurrentExp = $data['experince'];
 	}
 	$Sexp = $Sexp + $CurrentExp;
 	$Smoney = $Smoney + $CurrentMoney;
 	mysql_query("UPDATE users SET money='$Smoney',experince='$Sexp' WHERE username = '$user1'",$db);
 }
 header("Location:comm/index.php");
} else {
 include("login.php");
 print "<p align='center'><font face='" . $fface . "'>Invaild Username/Password</font></p>";
}	
}
?>

 

Thankz

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.