Mystical Posted June 13, 2011 Posted June 13, 2011 Trying to change the name of a house in v2.03 in staff panel you get this error.... QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query was SELECT `hID` FROM `houses` WHERE `hID` = How do I fix this? I put in the old staff_houses.php file from the old version v2.0.2c and it works so it must be something in v2.0.3 Here is the file that does not work from v2.0.3 <?php include_once "sglobals.php"; if ( $ir['user_level'] != 2 ) { echo 'You cannot access this area.<br />> <a href="staff.php">Go Back</a>'; die($h->endpage()); } //This contains shop stuffs switch($_GET['action']) { case "addhouse": addhouse(); break; case "edithouse": edithouse(); break; case "delhouse": delhouse(); break; default: echo "Error: This script requires an action."; break; } function addhouse() { global $db, $ir, $c, $h, $userid; $price = ( isset($_POST['price'])&&is_numeric($_POST['price']) )?abs(intval($_POST['price'])):''; $will = ( isset($_POST['will'])&&is_numeric($_POST['will']) )?abs(intval($_POST['will'])):''; $name = ( isset($_POST['name'])&&preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['name']) )?strip_tags($db->escape($_POST['name'])):''; if ( $price && $will && $name ) { $q = $db->query("SELECT `hID` FROM `houses` WHERE `hWILL` = {$will}"); if ( $db->num_rows($q) ) { echo 'Sorry, you cannot have two houses with the same maximum will.<br />> <a href="staff_houses.php?action=addhouse">Go Back</a>'; die($h->endpage()); } $db->query("INSERT INTO `houses` VALUES(NULL, '$name', '$price', '$will')"); stafflog_add('Created House '.$name); echo 'House '.$name.' added to the game.<br />> <a href="staff.php">Go Back</a>'; die($h->endpage()); } else { echo " <h3>Add House</h3> <hr /> <form action='staff_houses.php?action=addhouse' method='post'> Name: <input type='text' name='name' /><br /> Price: <input type='text' name='price' /><br /> Max Will: <input type='text' name='will' /><br /> <input type='submit' value='Add House' /> </form> "; } } function edithouse() { global $db, $ir, $c, $h, $userid; switch ( $_POST['step'] ) { case "2": $price = ( isset($_POST['price'])&&is_numeric($_POST['price']) )?abs(intval($_POST['price'])):''; $will = ( isset($_POST['will'])&&is_numeric($_POST['will']) )?abs(intval($_POST['will'])):''; $_POST['id'] = ( isset($_POST['id'])&&is_numeric($_POST['id']) )?abs(intval($_POST['id'])):''; $q = $db->query("SELECT `hID` FROM `houses` WHERE `hWILL` = {$will} AND `hID` != {$_POST['id']}"); if ( $db->num_rows($q) ) { echo 'Sorry, you cannot have two houses with the same maximum will.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); } $cnt_h = $db->query('SELECT `hID` FROM `houses` WHERE `hID` = '.$_POST['ID']); if ( $db->num_rows($cnt_h) == 0 ) { echo 'Invalid house.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); } $name = ( isset($_POST['name'])&&preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['name']) )?strip_tags($db->escape($_POST['name'])):''; $q = $db->query("SELECT `hWILL` FROM `houses` WHERE `hID` = {$_POST['id']}"); $old = $db->fetch_row($q); if ( $old['hWILL'] == 100 && $old['hWILL'] != $will ) { echo 'Sorry, this house\'s will bar cannot be edited.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); } $db->query("UPDATE `houses` SET `hWILL` = $will, `hPRICE` = $price, `hNAME` = '$name' WHERE `hID` = {$_POST['id']}"); $db->query("UPDATE `users` SET `maxwill` = $will WHERE `maxwill` = {$old['hWILL']}"); $db->query("UPDATE `users` SET `will` = `maxwill` WHERE `will` > `maxwill`"); stafflog_add('Edited house '.$name); echo 'House '.$name.' was edited successfully.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); break; case "1": $_POST['house'] = ( isset($_POST['house'])&&is_numeric($_POST['house']) )?abs(intval($_POST['house'])):''; $q = $db->query("SELECT `hWILL`,`hPRICE`,`hNAME` FROM `houses` WHERE `hID` = {$_POST['house']}"); if ( $db->num_rows($q) == 0 ) { echo 'Invalid house.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); } $old = $db->fetch_row($q); echo " <h3>Editing a House</h3> <hr /> <form action='staff_houses.php?action=edithouse' method='post'> <input type='hidden' name='step' value='2' /> <input type='hidden' name='id' value='{$_POST['house']}' /> Name: <input type='text' name='name' value='{$old['hNAME']}' /> Price: <input type='text' name='price' value='{$old['hPRICE']}' /> <br /> Max Will: <input type='text' name='will' value='{$old['hWILL']}' /> <br /> <input type='submit' value='Edit House' /> </form> "; break; default: echo " <h3>Editing a House</h3> <hr /> <form action='staff_houses.php?action=edithouse' method='post'> <input type='hidden' name='step' value='1' /> House: ".house_dropdown($c, "house")." <br /> <input type='submit' value='Edit House' /> </form> "; break; } } function delhouse() { global $db,$ir,$c,$h,$userid; $_POST['house'] = ( isset($_POST['house'])&&is_numeric($_POST['house']) )?abs(intval($_POST['house'])):''; if ( $_POST['house'] ) { $q = $db->query("SELECT `hWILL`,`hPRICE`,`hID`,`hNAME` FROM `houses` WHERE `hID` = {$_POST['house']}"); if ( $db->num_rows($q) == 0 ) { echo 'Invalid house.<br />> <a href="staff_houses.php?action=edithouse">Go Back</a>'; die($h->endpage()); } $old = $db->fetch_row($q); if ( $old['hWILL'] == 100 ) { echo 'This house cannot be deleted.<br />> <a href="staff_houses.php?action=delhouse">Go Back</a>'; die($h->endpage()); } $q2 = $db->query("SELECT `userid` FROM `users` WHERE `maxwill` = {$old['hWILL']}"); $ids = array(); while ( $r = $db->fetch_row($q2) ) { $ids[] = $r['userid']; } if ( count($ids) ) { $db->query("UPDATE `users` SET `money` = `money` +{$old['hPRICE']}, `maxwill` = 100 WHERE `userid` IN(".implode(', ', $ids).")"); } $db->query("UPDATE `users` SET `will` = `maxwill` WHERE `will` > `maxwill`"); $db->query("DELETE FROM `houses` WHERE `hID` = {$old['hID']}"); stafflog_add('Deleted house '.$old['hNAME']); echo 'House '.$old['hNAME'].' deleted.<br />> <a href="staff_houses.php?action=delhouse">Go Back</a>'; die($h->endpage()); } else { echo " <h3>Delete House</h3><hr /> Deleting a house is permanent - be sure. Any users that are currently on the house you delete will be returned to the first house, and their money will be refunded. <form action='staff_houses.php?action=delhouse' method='post'> House: ".house_dropdown($c, "house")." <br /> <input type='submit' value='Delete House' /> </form> "; } } $h->endpage(); ?> Quote
Uridium Posted June 13, 2011 Posted June 13, 2011 change $cnt_h = $db->query('SELECT `hID` FROM `houses` WHERE `hID` = '.$_POST['ID']); to on line 54 $cnt_h = $db->query('SELECT `hID` FROM `houses` WHERE `hID` = '.$_POST['id']); Quote
Mystical Posted June 13, 2011 Author Posted June 13, 2011 change $cnt_h = $db->query('SELECT `hID` FROM `houses` WHERE `hID` = '.$_POST['ID']); to on line 54 $cnt_h = $db->query('SELECT `hID` FROM `houses` WHERE `hID` = '.$_POST['id']); Thanks a million illusions! Works like a charm. I looked at that file for 3 hours trying to compare the 2 files and could not find it. Thanks again. 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.