Jump to content

Recommended Posts

hello.

 

i am looping throught a select form and want to add a title as the top option that does nothing when submitted but its giving me an 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 'LIMIT 1' at line 1

 

i guess thats because it has no id .

 

how do i make it so if the option says "Select a Property Type..." it gives an error message saying to select an option if submitted. plus get rid of that error?

 

thanks

rick

 

 

<form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 <table class="properties" width="550" border="0" cellspacing="0" cellpadding="0">
	 <tr> <td width="350">

		 <?php
		 $propType = Prop_Types::find_all();
		 $idSelectedByUser = (isset($_GET['propType']) ? $_GET['propType'] : '');
		 echo "<select id='propType' 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 == $idSelectedByUser ? " SELECTED='SELECTED' " : "") .
			 ">" . $pType->name . "</option>";
		 }
		 echo "</select>";
		 ?>
		  <input type="submit" name="submitPropType" value="Select" class="submitBTN"/>
     	   </td>


	 <?php
	 if($_GET){
	 $propTypes = Prop_Types::find_by_id($idSelectedByUser);
	 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>';
 }
 ?>
</tr>
</table>
</form>

Link to comment
https://forums.phpfreaks.com/topic/272094-form-select-loop-error/
Share on other sites

that worked :)

 

  <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 id='propType' 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 . "</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 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.