stockychaser Posted February 27, 2011 Share Posted February 27, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/ Share on other sites More sharing options...
Fergal Andrews Posted February 27, 2011 Share Posted February 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180245 Share on other sites More sharing options...
stockychaser Posted February 27, 2011 Author Share Posted February 27, 2011 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180348 Share on other sites More sharing options...
stockychaser Posted February 27, 2011 Author Share Posted February 27, 2011 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180403 Share on other sites More sharing options...
Fergal Andrews Posted February 27, 2011 Share Posted February 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180413 Share on other sites More sharing options...
stockychaser Posted February 27, 2011 Author Share Posted February 27, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180493 Share on other sites More sharing options...
Fergal Andrews Posted February 27, 2011 Share Posted February 27, 2011 Hi stockychaser, glad you got it sorted. All the best, Fergal Quote Link to comment https://forums.phpfreaks.com/topic/228990-populating-of-drop-down-menu-not-working/#findComment-1180519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.