DropList problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

DropList problem

Post by galligraph »

Could semeone help me?

I'm using PHP with MySql. I got a DropList where's 4 options. If i choose one of the 3 first options the value should go to the database. If i choose option 4 i need 2 write something 2 the textarea and the text should go 2 the database. So if u have written somethin' 2 the textarea and the option 4 is not chosen the text don't go 2 the database. So simple question is... How 2 make the post code or do i have 2 change something else?

Code: Select all

<select name='answer'>"; 
	echo "<option value='yes'>Yes</option> ";
	echo "<option value='no'>No</option> ";
	echo "<option value='else'>Else</option> ";
	echo "<option value='text'>Text</option> ";
	echo "</select>"; 

	echo "<textarea name='textanswer' colls='2' rows='5'></textarea>";
LazyJones
Forum Newbie
Posts: 5
Joined: Tue Dec 27, 2005 8:56 pm

Re: DropList problem

Post by LazyJones »

Code: Select all

if(($_POST['answer'] == "text") && ($_POST['textanswer'] != "")) {
	// write to database
}
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

Thx a lot LazyJones :wink: Answer was quick and that was exactly what i was lookin' 4...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Erm... code probably throws a E_NOTICE. May I suggest checking for the existence of the variables before using them?

Edit

Code: Select all

if((isset($_POST['answer']) && $_POST['answer'] == "text") &&
   (isset($_POST['textanswer']) && $_POST['textanswer'] !== '')) {
   // write to database
}
Instill good coding practices!
Post Reply