Jump to content

Mutli Form Submits In Select Dropdown


ricky spires

Recommended Posts

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>


Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

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.

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.