Jump to content

Recommended Posts

trying to get a drop-down menu (in a form) to work  that needs to get populated from a table

table called  :  CarCategory

in this table are 2 columns  called

CarCategoryID    (unique number from 1-18)

CarCategoryDesc  (actual name of category.. e.g. 'convertible')

 

link :  http://98.131.37.90/postPart.php

 

I'm a total novice.. and can't figure out why the first is not working and the second (country) is working

 

 

code :

 

<!--NOT WORKING ... why not ?? should show drop down menu--> 

    <label>

      <div align="center">

          <select name="carcategory" id="CarCategory" class="validate[required]" style="width: 200px;">

 

          <option value="">Select Car Category from list...</option>

 

            <?php while($obj_queryCarCategory = mysql_fetch_object($result_queryCarCategory)) { ?>

                <option value="<?php echo $obj_queryCarCategory->CarCategoryID;?>"

                <?php if($obj_queryCarCategory->CarCategoryID == $UserCountry) { echo 'selected="selected"'; } ?> >

                <?php echo $obj_queryCarCategory->CarCategoryDesc;?></option>

            <?php } ?>

 

        </select>

      </div>

    </label>

 

<!-- working ! -->

    <label>

      <div align="center">

          <select name="country" id="Country" class="validate[required]" style="width: 200px;">

 

          <option value="">Select...</option>

 

            <?php while($obj_queryCountry = mysql_fetch_object($result_queryCountry)) { ?>

                <option value="<?php echo $obj_queryCountry->CountryID;?>"

                <?php if($obj_queryCountry->CountryID == $UserCountry) { echo 'selected="selected"'; } ?> >

                <?php echo $obj_queryCountry->CountryName;?></option>

            <?php } ?>

 

        </select>

      </div>

    </label>

 

Hi stockychaser,

I can't see the country drop-down in the page you link to. Are you definitely getting a connection to your database?

Try putting some debugging code in to see if you are getting any results.

 

Use var_dump() to view the content of $obj_queryCarCategory

 

 <?php while($obj_queryCarCategory = mysql_fetch_object($result_queryCarCategory)) { var_dump($obj_queryCarCategory); ?>

 

Can you post the code that does the database connection and query?

 

Cheers,

Fergal

 

oh I'm very sorry... I changed the page, thinking it would work if only 1 drop-down menu was on there, however...that did not change anything.

please look again...

http://98.131.37.90/postPart.php

 

the second drop-down does work !

hi Fergal,

the connection looks like this :

 

<?php

 

    // information about Mysql server

    $dbhost = '98.130.0.104';

    $dbuser = 'soundfa_sam';

    $dbpass = '********';      //here sits the correct password !

    $dbname = 'soundfa_acn';

 

    // try to connect

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());

 

    // choose database

    mysql_select_db($dbname);

?>

 

 

- - - - -

 

When I insert the php string you gave me above, the page no longer loads.

is this normal ? (again... I'm totally new to PHP !! (sorry))

 

thanks all !

Hi stockychaser,

Your connection code looks fine.

 

If you're getting a blank page it is probably because error reporting is turned off. Try inserting this at the top of your script:

 

error_reporting(E_ALL);
ini_set('display_errors','On');

 

If you have direct access to the database  try running your SQL query directly to make sure it doesn't contain any errors.

 

Fergal

It's working. .

 

at the top of the page... I forgot to put in the "getCarCategory" section :(

 

 

 

<?php

    // start session

    session_start();

 

    // Include site's config

    include_once 'phpcodes/config.php';

 

    // Include connection

    include_once 'phpcodes/conn.php';

 

    // get Currency

    $sql_queryCurrency = 'SELECT * FROM Currency';

    $result_queryCurrency = mysql_query($sql_queryCurrency) or die (mysql_error());

 

    // get CarMake

    $sql_queryCarMake = 'SELECT * FROM CarMake';

    $result_queryCarMake = mysql_query($sql_queryCarMake) or die (mysql_error());

 

    // get CarCategory

    $sql_queryCarCategory = 'SELECT * FROM CarCategory';

    $result_queryCarCategory = mysql_query($sql_queryCarCategory) or die (mysql_error());

 

    // get CarModel

    $sql_queryCarModel = 'SELECT * FROM CarModel';

    $result_queryCarModel = mysql_query($sql_queryCarModel) or die (mysql_error());

 

 

?>

 

 

thanks for all the help...

 

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.