johnnybravo Posted May 15, 2007 Share Posted May 15, 2007 Hi guys... I'm building a content management system using PHP and MySQL so that we can add and remove projects from our website easily. I want several dropdown lists with the options Yes/No (or radio buttons, whichever is easiest) in them and depending on the users choice it will add their choice into the db. I have the Add page working fine, but the problem lies in the update page. if i go to my update page it pulls all the right information back into the HTML form from the DB until it gets to the dropdowns, which it doesnt like. How can i make it select the appropriate option from the dropdowns depending on the DB? If i submit the changes it wont update it either and gives errors from the dropdown code. The code im using for the Add is as follows: <select name="ServiceWeb" class="admin_form"> <option value="No" selected="selected">No</option> <option value="Yes">Yes</option> </select> and the problem code for the Update page <select name="ServiceWeb" class="admin_form"> <?php if ($ServiceWeb=="Yes") { ?> <option value="No">No</option> <option value="Yes" selected="selected">Yes</option> <?php } else { ?> <option value="No" selected="selected">No</option> <option value="Yes">Yes</option> <?php } ?> </select> Another thing to mention is that in the MySQL db i have the entry for ServiceWeb set to TEXT at the moment, this can be changed however you see fit! hope this all makes sense, im sure what im trying to do is SO simple but i have been struggling with it all morning. thanks John Quote Link to comment https://forums.phpfreaks.com/topic/51519-html-form-with-php-and-mysql/ Share on other sites More sharing options...
clown[NOR] Posted May 15, 2007 Share Posted May 15, 2007 this might work... <select name="ServiceWeb" class="admin_form"> <?php echo ' <option value="No"'; if ($ServiceWeb == "no") { echo "selected=selected"; } echo '>No</option> <option value="Yes"'; if ($ServiceWeb == "yes") { echo "selected=selected"; } echo '>Yes</option> '; ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/51519-html-form-with-php-and-mysql/#findComment-253743 Share on other sites More sharing options...
johnnybravo Posted May 15, 2007 Author Share Posted May 15, 2007 This kind of works, well it gets the data from the database and updates the relevant dropdown selections but if i re-submit the form to write new selections to the database it doesnt do it, it just resets the values to nothing. any ideas? In short i want to be able to update database when i click submit with any modifed changes thanks J Quote Link to comment https://forums.phpfreaks.com/topic/51519-html-form-with-php-and-mysql/#findComment-253774 Share on other sites More sharing options...
johnnybravo Posted May 15, 2007 Author Share Posted May 15, 2007 ignore my last comment i have it working now with the code supplied, thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/51519-html-form-with-php-and-mysql/#findComment-253779 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.