corruptcity || skalman Posted March 27, 2010 Posted March 27, 2010 hi im stuck on this function for my next up and coming freebie its a car mod here is the function where you select the car that you want to race with and there is just 1 problem im having with it but looking at it it should work but doesnt ill comment around where the problem is and what the problem is. yes ino its not as secure as it can be but i go through securing more after ive finished the function. if you need any other info or quest feel free to ask and thanks function usecar() { global $db, $ir,$c,$userid,$h; $_GET['ID'] = isset($_GET['ID']) && is_numeric($_GET['ID']) ? abs((int) $_GET['ID']) : false; if($_GET['ID']) { $use=$db->query(sprintf("SELECT * FROM cars_use WHERE (CU_USERID = %d)", $ir['userid'])); if($db->num_rows($use) == 1) { echo"You cant use more than 1 car at once"; $h->endpage(); exit; } else { $car=$db->query(sprintf("SELECT * FROM cars_inv WHERE (CI_ID = %d) AND (CI_USERID = %d)", $_GET['ID'], $ir['useird'])); if($db->num_Rows($car) == 1) { echo"You dont own that car"; $h->endpage(); exit; } //problems starts here onwards when you run the code $carid = nothing so does $cars and $newcars = -1 $p=$db->fetch_row($car); $carid = ($p['CI_CAR']); $cars = ($p['CI_QTY']); $newcars = ($cars-1); if($p['CI_QTY'] > 1) { $db->query(sprintf("DELETE FROM cars_inv WHERE (CI_ID = %d), (CI_USERID = %d)", $_GET['ID'], $ir['userid'])); $db->query(sprintf("INSERT INTO cars_inv (CI_ID, CI_USERID, CI_CAR, CI_QTY) VALUES (%d, %d, %d, %d)", '', $ir['userid'], $carid, $newcars)); $db->query(sprintf("INSERT INTO cars_use (CU_ID, CU_USERID, CU_CAR) VALUES (%d, %d, %d)", '', $ir['userid'], $carid)); echo"You have set the car that you want to drive {$carid}, {$cars}, {$newcars}"; // the 3 {} were for me testing what was in the vars nothing else } else { $db->query(sprintf("DELETE FROM cars_inv WHERE (CI_ID = %d) AND (CI_USERID = %d)", $_GET['ID'], $ir['useird'])); $db->query(sprintf("INSERT INTO cars_use (CU_ID, CU_USERID, CU_CAR) VALUES (%d, %d, %d)", '', $ir['userid'], $d['CI_CAR'])); echo"You have set the car that you want to drive {$carid}, {$cars}, {$newcars}";// the 3 {} were for me testing what was in the vars nothing else } } } //just with the bit of code between the comments else { $yourcars=$db->query("SELECT c.*, ci.* FROM cars_inv ci LEFT JOIN cars c ON ci.CI_CAR=c.carid WHERE CI_USERID=$userid"); if($db->num_rows($yourcars) == 0) { echo"You dont own any cars yet!"; $h->endpage(); exit; } else { echo"<table> <tr> <th>Manufacture <th>Model <th>Year <th>Qty <th>Price <th>Total Price <th>HP <th>Accell <th>Speed <th>Handling <th>Brakes <th>Use Car </tr>"; while($r=$db->fetch_row($yourcars)) { $totalprice = ($r['CI_QTY'] * $r['price']); echo"<tr> <td><center>{$r['manufacture']}</center></td> <td><center>{$r['model']}</center></td> <td><center>{$r['year']}</center></td> <td><center>{$r['CI_QTY']}</center></td> <td><center>\${$r['price']}</center></td> <td><center>\${$totalprice}</center></td> <td><center>{$r['HP']}</center></td> <td><center>{$r['accell']}</center></td> <td><center>{$r['speed']}</center></td> <td><center>{$r['handling']}</center></td> <td><center>{$r['brakes']}</center></td> <td><center>[url='cars.php?action=usecar&ID={$r[']Use Car[/url]</center></td> </tr>"; } echo"</table>"; } } } Quote
Guest Drizzle Posted March 27, 2010 Posted March 27, 2010 I believe its INSERT(stuff here, like column names) INTO tables VAULES(values) Quote
Guest Drizzle Posted March 27, 2010 Posted March 27, 2010 oh and whats with the parentheses around your variables? could that be the problem ? :/ Quote
Danny696 Posted March 27, 2010 Posted March 27, 2010 I believe its INSERT(stuff here, like column names) INTO tables VAULES(values) Incorrect. And whats the error, whould help Quote
Lithium Posted March 27, 2010 Posted March 27, 2010 $db->query(sprintf("DELETE FROM cars_inv WHERE (CI_ID = %d) AND (CI_USERID = %d)", $_GET['ID'], $ir['useird'])); $ir['userid'] not $ir['useird'] That seems to be the only problem at sight, other than that please post the error! Quote
corruptcity || skalman Posted March 27, 2010 Author Posted March 27, 2010 ok thanks danny and lithium for the help cant believe that was staring me right in the face all last night and just show i cant code when im tried as ive fixed this function it can be delete now mods Quote
corruptcity || skalman Posted March 27, 2010 Author Posted March 27, 2010 dany it doesnt give me any problems doing it the way i do it tho it prob is a bad coding habit to have lol I.E $db->query(sprintf("INSERT INTO cars_inv (CI_ID, CI_USERID, CI_CAR, CI_QTY) VALUES (%d, %d, %d, %d)", ' ', $ir['userid'], $carid, $newcars)); Quote
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.