ricky spires Posted December 18, 2012 Share Posted December 18, 2012 mutli form submits in select dropdown? hello. im totally stuck. i need to create a drop down that lets me edit/delete the selected item but im so so so stuck i think its to do with the multi submit buttons at the moment when you select the first option, it works fine. its puts the corrct information in to the secont drop down but when you select the second drop down i get this error Database query failed: 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 'ORDER BY name' at line 1 this is the code <form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label><b>Property Types:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_prop_type.php">Add</a>'; } ?> </td> <td width="315"> <?php $propType = Prop_Types::find_all(); $getPropType = (isset($_GET['propType']) ? $_GET['propType'] : ''); echo "<select name='propType' class='select1css required'>"; echo "<option name='' value='' >Select a Property Type...</option>"; foreach($propType as $pType) { echo "<option name='" . $pType->name . "' value='" . $pType->id . "'" .($pType->id == $getPropType ? " SELECTED='SELECTED' " : "Select a Property Type...") . ">" . $pType->name . "" . $pType->id . "</option>"; } echo "</select>"; ?> <?php if($getPropType <1){ echo'<input type="submit" name="submitPropType" value="Select" class="submitBTN"/>'; } ?> </td> <?php if($getPropType){ $propTypes = Prop_Types::find_by_id($getPropType); echo '<td>You selected:'.$propTypes->name; echo '<br><a href="edit_prop_type.php?id='.$_GET['propType'].'">Edit</a> - <a href="delete_prop_type.php?id='.$_GET['propType'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Property type</span></td>'; } ?> </tr> </table> </form> <form name="submitCats" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label><b>Categories:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_category.php">Add</a>'; } ?> </td> <td width="315"> <?php $cats = Cats::find_by_parent($getPropType); $getCats = (isset($_GET['cats']) ? $_GET['cats'] : ''); echo "<select name='cats' class='select1css required'>"; echo "<option value='Select a Category' >Select a Category...</option>"; foreach($cats as $cat) { echo "<option>".$cat->name."</option>"; } echo "</select>"; ?> <input type="submit" name="submitCats" value="Select" class="submitBTN"/> </td> <?php if($getCats){ $cats = Cats::find_by_id($getCats); echo '<td>You selected:'.$cats->name; echo '<br><a href="edit_Categories.php?id='.$_GET['cats'].'">Edit</a> - <a href="delete_Categories.php?id='.$_GET['cats'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Category</span></td>'; } ?> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/ Share on other sites More sharing options...
ricky spires Posted December 18, 2012 Author Share Posted December 18, 2012 please also not that the forms are pulling from different databases Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400071 Share on other sites More sharing options...
Muddy_Funster Posted December 18, 2012 Share Posted December 18, 2012 wheres the actual SQL? Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400074 Share on other sites More sharing options...
ricky spires Posted December 18, 2012 Author Share Posted December 18, 2012 in classes Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400081 Share on other sites More sharing options...
Muddy_Funster Posted December 18, 2012 Share Posted December 18, 2012 You don't think that, since the error is with the SQL, it may be helpfull if we could see those classes? Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400087 Share on other sites More sharing options...
ricky spires Posted December 18, 2012 Author Share Posted December 18, 2012 ok. here we go. there is alot This is the page that displays the drop downs <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $currentUser = User::find_by_id($_SESSION['user_id']); ?> <?php include_layout_template('admin_header.php'); ?> <div id="adminWrapper"> <div class="adminLeft"><?php include_layout_template('admin_leftCol.php'); ?></div> <h2>PROPERTIES</h2> <?php echo output_message($message); ?> <?php include("includes/prop-type.php"); include("includes/prop-cats.php"); ?> </div> <?php include_layout_template('admin_footer.php'); ?> This is the include page for form1 <form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label><b>Property Types:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_prop_type.php">Add</a>'; } ?> </td> <td width="315"> <?php $propType = Prop_Types::find_all(); $getPropType = (isset($_GET['propType']) ? $_GET['propType'] : ''); echo "<select name='propType' class='select1css required'>"; echo "<option name='' value='' >Select a Property Type...</option>"; foreach($propType as $pType) { echo "<option name='" . $pType->name . "' value='" . $pType->id . "'" .($pType->id == $getPropType ? " SELECTED='SELECTED' " : "Select a Property Type...") . ">" . $pType->name . "" . $pType->id . "</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropType" value="Select" class="submitBTN"/> </td> <?php if($getPropType){ $propTypes = Prop_Types::find_by_id($getPropType); echo '<td>You selected:'.$propTypes->name; echo '<br><a href="edit_prop_type.php?id='.$_GET['propType'].'">Edit</a> - <a href="delete_prop_type.php?id='.$_GET['propType'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Property type</span></td>'; } ?> </tr> </table> </form> This is the include page for form 2 <?php require_once("../../includes/initialize.php"); ?> <form name="submitCats" method="GET" action=""> <label><b>Categories:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_category.php">Add</a>'; } ?> </td> <td width="315"> <?php echo $getPropType; $propCats = Cats::find_all(); //$propCats = Cats::find_by_parent($getPropType); $getPropCats = (isset($_GET['propCats']) ? $_GET['propCats'] : ''); echo "<select name='propCats' class='select1css required'>"; echo "<option name='' value='' >Select a Category...</option>"; foreach($propCats as $pCats) { echo "<option name='" . $pCats->name . "' value='" . $pCats->id . "'" .($pCats->id == $getPropCats ? " SELECTED='SELECTED' " : "") . ">" . $pCats->name . "" . $pCats->id . "</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropCats" value="Select" class="submitBTN"/> </td> <?php if($getPropCats){ $propCats = Cats::find_by_id($getPropCats); echo '<td>You selected:'.$propCats->name; echo '<br><a href="edit_prop_Cats.php?id='.$_GET['propCats'].'">Edit</a> - <a href="delete_prop_Cats.php?id='.$_GET['propCats'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Category</span></td>'; } ?> </tr> </table> </form> This is part od the class of the first form <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH.DS.'database.php'); class Prop_Types extends DatabaseObject { protected static $table_name="prop_type"; protected static $db_fields = array('id','name','created', 'modified'); public $id; public $name; public $created; public $modified; // Common Database Methods public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name." ORDER BY name"); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} ORDER BY name LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } This is part of the class for the second form <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH.DS.'database.php'); class Cats extends DatabaseObject { protected static $table_name="prop_cats"; protected static $db_fields = array('id', 'type_id', 'name', 'created', 'modified'); public $id; public $type_id; public $name; public $created; public $modified; // Common Database Methods public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name." ORDER BY name"); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} ORDER BY name LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } public static function find_by_parent($catParent) { return self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE type_id={$catParent} ORDER BY name"); } Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400094 Share on other sites More sharing options...
ricky spires Posted December 18, 2012 Author Share Posted December 18, 2012 the problem seems to be that when i press the second submit button it refreshes the first Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400097 Share on other sites More sharing options...
Muddy_Funster Posted December 18, 2012 Share Posted December 18, 2012 you are setting to $getPropCats to an empty string in it's not in the url, so in these events, when you pass that to the query you are for CATS::find_by_parent you will end up with the query SELECT * FROM prop_cats WHERE type_id= ORDER BY name In the assumed or die() part of the find_by_sql() output the query string as it was sent to the DB and you should see what's going on better. Quote Link to comment https://forums.phpfreaks.com/topic/272137-mutli-form-submits-in-select-dropdown/#findComment-1400103 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.