Dragon Blade Posted January 22, 2014 Share Posted January 22, 2014 (edited) Hello all, I have a problem when I race in game. If the person who sends the challenge, and the other person accepted it. The person who sent the challenge wins? Can someone fix this for me? <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $cm=money_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); // Security check $id=abs((int) $_POST['id']); $car=abs((int) $_POST['car']); if(!$id || !$car) { print "<hr width='50%'>Please read the error message.<hr width='50%'><h3>! ERROR</h3>Invalid usage.<br /><br /> <hr width='50%'><a href='index.php'>> Go Home</a><hr width='50%'><br />"; $h->endpage(); exit; } // End $q=mysql_query("SELECT ch.*, cp.*, ct.*, u1.username as challenger, u2.username as challenged FROM challenges ch LEFT JOIN cars_playercars cp ON ch.chCHRCAR=cp.cpcID LEFT JOIN cars_types ct ON ct.carID=cp.cpcCAR LEFT JOIN users u1 ON ch.chCHR=u1.userid LEFT JOIN users u2 ON ch.chCHD=u2.userid WHERE ch.chID={$id} AND (ch.chCHR=$userid OR ch.chCHD=$userid)"); if(mysql_num_rows($q) == 0) { print "<hr width='50%'>Please read the error message.<hr width='50%'><h3>! ERROR</h3>Invalid challenge.<br /><br /> <hr width='50%'><a href='index.php'>> Go Home</a><hr width='50%'><br />"; $h->endpage(); exit; } $r=mysql_fetch_array($q); if($r['chSTATUS']=="open") { $bet=$r['chBET']; if($bet > $ir['money']) { print "<hr width='50%'>Please read the error message.<hr width='50%'><h3>! ERROR</h3>The bet is too large.<br /><br /> <hr width='50%'><a href='index.php'>> Go Home</a><hr width='50%'><br />"; $h->endpage(); exit; } $q=mysql_query("SELECT cp.*,ct.* FROM cars_playercars cp LEFT JOIN cars_types ct ON ct.carID=cp.cpcCAR WHERE cp.cpcID={$car} AND cp.cpcPLAYER=$userid"); if(mysql_num_rows($q) == 0) { print "<hr width='50%'>Please read the error message.<hr width='50%'><h3>! ERROR</h3>Invalid car.<br /><br /> <hr width='50%'><a href='index.php'>> Go Home</a><hr width='50%'><br />"; $h->endpage(); exit; } $m=mysql_fetch_array($q); if($m['cpcID'] == $r['cpcID']) { print "<hr width='50%'>Please read the error message.<hr width='50%'><h3>! ERROR</h3>????<br /><br /> <hr width='50%'><a href='index.php'>> Go Home</a><hr width='50%'><br />"; $h->endpage(); exit; } //kk, time to race =D print "<hr width='50%'>Please read the confirmation message.<hr width='50%'><h3>! CONFIRMATION</h3>You will receive the results of this race in an event.<br /><br /> <hr width='50%'><a href='events.php'>> Go Back</a><hr width='50%'><br />"; mysql_query("UPDATE users SET money=money-$bet WHERE userid={$userid}"); $q=mysql_query("SELECT * FROM cars_tracks ORDER BY rand() LIMIT 1"); $t=mysql_fetch_row($q); $stats_y=0; $stats_y+=$m['cpcACCLV']*$m['carACC']*$t['ctrkACC']; $stats_y+=$m['cpcHANLV']*$m['carHAN']*$t['ctrkHAN']; $stats_y+=$m['cpcSPDLV']*$m['carSPD']*$t['ctrkSPD']; $stats_y+=$m['cpcSHDLV']*$m['carSHD']*$t['ctrkSHD']; $stats_o=0; $stats_o+=$r['cpcACCLV']*$r['carACC']*$t['ctrkACC']; $stats_o+=$r['cpcHANLV']*$r['carHAN']*$t['ctrkHAN']; $stats_o+=$r['cpcSPDLV']*$r['carSPD']*$t['ctrkSPD']; $stats_o+=$r['cpcSHDLV']*$r['carSHD']*$t['ctrkSHD']; $stats_y*=rand(800,1200); $stats_o*=rand(800,1200); $notes="No-one won anything"; mysql_query("UPDATE users SET cars_challs_accpt=cars_challs_accpt+1 WHERE userid=$userid"); if($stats_y > $stats_o) { $winner=$ir['username']; $winnings=$bet*2; mysql_query("UPDATE users SET money=money+$winnings, cars_races_income=cars_races_income+$bet,cars_races_won=cars_races_won+1 WHERE userid={$r['chCHD']}"); mysql_query("UPDATE users SET cars_races_income=cars_races_income-$bet,cars_races_lost=cars_races_lost+1 WHERE userid={$r['chCHR']}"); if($bet > 0) { $notes="{$r['challenged']} won \$$winnings"; } if($r['chTYPE'] == "High-Stakes") { mysql_query("UPDATE cars_playercars SET cpcPLAYER=$userid WHERE cpcID={$r['cpcID']}"); $notes="{$r['challenged']} won {$r['challenger']}\'s {$r['carNAME']}"; mysql_query("UPDATE users SET cars_lost=cars_lost+1 WHERE userid={$r['chCHR']}"); mysql_query("UPDATE users SET cars_won=cars_won+1,cars_owned=cars_owned+1 WHERE userid={$r['chCHD']}"); } else if($r['chTYPE'] == "Betted") { mysql_query("UPDATE users SET cars_races_betted=cars_races_betted+1 WHERE userid IN ({$r['chCHR']}, {$r['chCHD']})"); } else { mysql_query("UPDATE users SET cars_races_friendly=cars_races_friendly+1 WHERE userid IN ({$r['chCHR']}, {$r['chCHD']})"); } } else { $winner=$r['challenger']; $winnings=$bet*2; if($bet > 0) { $notes="{$r['challenger']} won \$$winnings"; } mysql_query("UPDATE users SET money=money+$winnings, cars_races_income=cars_races_income+$bet,cars_races_won=cars_races_won+1 WHERE userid={$r['chCHR']}"); mysql_query("UPDATE users SET cars_races_income=cars_races_income-$bet,cars_races_lost=cars_races_lost+1 WHERE userid={$r['chCHD']}"); if($r['chTYPE'] == "High-Stakes") { mysql_query("UPDATE cars_playercars SET cpcPLAYER={$r['chCHR']} WHERE cpcID={$m['cpcID']}"); $notes="{$r['challenger']} won {$r['challenged']}\'s {$m['carNAME']}"; mysql_query("UPDATE users SET cars_lost=cars_lost+1 WHERE userid={$r['chCHD']}"); mysql_query("UPDATE users SET cars_won=cars_won+1,cars_owned=cars_owned+1 WHERE userid={$r['chCHR']}"); } else if($r['chTYPE'] == "Betted") { mysql_query("UPDATE users SET cars_races_betted=cars_races_betted+1 WHERE userid IN ({$r['chCHR']}, {$r['chCHD']})"); } else { mysql_query("UPDATE users SET cars_races_friendly=cars_races_friendly+1 WHERE userid IN ({$r['chCHR']}, {$r['chCHD']})"); } } $challengercar=$r['carNAME']; $challengedcar=$m['carNAME']; mysql_query("INSERT INTO race_results VALUES('', '{$r['chTYPE']}', '{$r['chBET']}', '{$r['challenger']}', '{$r['challenged']}', '$challengercar', '$challengedcar','$winner', '$notes')", $c); $i=mysql_insert_id($c); event_add($r['chCHR'], "Your race with <a href='viewuser.php?u={$r['chCHD']}'>{$r['challenged']}</a> is finished. Click <a href='viewrace.php?race={$i}'><font color='green'>here</font></a> to view the results.</a>"); event_add($r['chCHD'], "Your race with <a href='viewuser.php?u={$r['chCHR']}'>{$r['challenger']}</a> is finished. Click <a href='viewrace.php?race={$i}'><font color='green'>here</font></a> to view the results.</a>"); mysql_query("UPDATE challenges SET chSTATUS='accepted' WHERE chID={$id}"); } $h->endpage(); ?> Edited January 23, 2014 by KyleMassacre added code tags Quote Link to comment Share on other sites More sharing options...
benlucraft Posted April 30, 2014 Share Posted April 30, 2014 Check your databases and query's in the code I think there is something there... 1 Quote Link to comment Share on other sites More sharing options...
SRB Posted April 30, 2014 Share Posted April 30, 2014 Check your databases and query's in the code I think there is something there... So, we not only resurrect a 2 month old thread that's dead, but equate the problem to either the code or the database... Leaving... Nothing. It can't be anything but the code or database, so I assume it's a post count boost of a post. Quote Link to comment Share on other sites More sharing options...
benlucraft Posted April 30, 2014 Share Posted April 30, 2014 No I'm just trying to help, I saw no one replied so I thought I would give it a go, I am not trying to boost my posts 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.