Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51519-html-form-with-php-and-mysql/
Share on other sites

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>

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

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.