Help - Search - Members - Calendar
Full Version: [PHP] Undefined index:
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
ABEO
I have a quick search form on a property website, on Firefox and IE7 I get an Undefined Index error.

CODE
Notice: Undefined index: cboPrice in /home/fhlinux159/s/spanishhomesjustforyou.com/user/htdocs/ssi/quiksearch.php</b> on line 16


I am getting this on several lines of code, all of which are drop down boxes, all with very similar code.

Here is line 16:
CODE
<option value="null"<?php if (!(strcmp("null", $_GET['cboRegion']))) {echo " selected='selected'";} ?>>Any Region...</option>



If anyone has any information on this, or can help out, I would be very grateful, let me know if you need anymore info.

Thanks
kittypaws
Generally the look to the line above the one that you are given.

You are probably giving an option for cboPrice and cboPrice does not exist as part of $_GET like $_GET['cboRegion']

the best way to check is not string comparing them with nulll, but doing a double check.. I provide this function for you:

CODE
function DoYouExist($variable) {
return (isset($variable) && !empty($variable));
}


pass your check to this to see if it it exists and is not empty.. (string comparing to null is an empty check..)

Kittypaws
ABEO
This is the full code for the whole form:

CODE
    <form id="fade" class="viz" style="width:680px; filter:progid:DXImageTransform.Microsoft.Fade(duration=2); -moz-opacity:0;" method="get" action="search-results.php">
        
    <select name="cboRegion" id="cboRegion">
        <option value="null"<?php if (!(strcmp("null", $_GET['cboRegion']))) {echo " selected='selected'";} ?>>Any Region...</option>
        <option value="Blanca"<?php if (!(strcmp("Blanca", $_GET['cboRegion']))) {echo " selected='selected'";} ?>>Costa Blanca</option>
        <option value="Calida"<?php if (!(strcmp("Calida", $_GET['cboRegion']))) {echo " selected='selected'";} ?>>Costa Calida</option>
    </select>

        
    <select name="cboPropType" id="cboPropType">
        <option value="null"<?php if (!(strcmp("null", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Any Property Type...</option>
        <option value="Apartment"<?php if (!(strcmp("Apartment", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Apartment</option>
        <option value="Bungalow"<?php if (!(strcmp("Bungalow", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Bungalow</option>
        <option value="Commercial"<?php if (!(strcmp("Commercial", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Commercial</option>
        <option value="Duplex"<?php if (!(strcmp("Duplex", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Duplex</option>
        <option value="Finca"<?php if (!(strcmp("Finca", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Finca</option>
        <option value="House"<?php if (!(strcmp("House", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>House</option>
        <option value="Villa"<?php if (!(strcmp("Villa", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Villa</option>
        <option value="Quad"<?php if (!(strcmp("Quad", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Quad</option>
        <option value="Other"<?php if (!(strcmp("Other", $_GET['cboPropType']))) {echo " selected='selected'";} ?>>Other</option>
    </select>

    <select name="cboStatus" id="cboStatus">
        <option value="null"<?php if (!(strcmp("null", $_GET['cboStatus']))) {echo " selected='selected'";} ?>>Any Status...</option>
        <option value="New"<?php if (!(strcmp("New", $_GET['cboStatus']))) {echo " selected='selected'";} ?>>New</option>
        <option value="Resale"<?php if (!(strcmp("Resale", $_GET['cboStatus']))) {echo " selected='selected'";} ?>>Resale</option>
      </select>
    <span class="viz" style="width:680px; filter:progid:DXImageTransform.Microsoft.Fade(duration=2); -moz-opacity:0;">
    <select name="cboPrice">
      <option value="null"<?php if (!(strcmp("null", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>Any Price...</option>
      <option value="0"<?php if (!(strcmp("0", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>0 - 100.000</option>
      <option value="100000"<?php if (!(strcmp("100000", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>100.000 - 140.000</option>
      <option value="140000"<?php if (!(strcmp("140000", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>140.000 - 180.000</option>
      <option value="180000"<?php if (!(strcmp("180000", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>180.000 - 220.000</option>
      <option value="220000"<?php if (!(strcmp("220000", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>220.000 - 260.000</option>
      <option value="260000"<?php if (!(strcmp("260000", $_GET['cboPrice']))) {echo " selected='selected'";} ?>>260.000++</option>
    </select>
    </span>
    <input class="submit" type="submit" value="SEARCH" />
    </form>


Where do I put that check code?
I am an absolute novice at this by the way, thanks for replying.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.