ricky spires Posted December 17, 2012 Share Posted December 17, 2012 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 More sharing options...
ricky spires Posted December 17, 2012 Author Share Posted December 17, 2012 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> Link to comment https://forums.phpfreaks.com/topic/272094-form-select-loop-error/#findComment-1399855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.