Hi ppl,

I am trying to save the details of a form on clicking submit into a database. the details entered in text box get saved, but the options chosen from drop down are not getting saved. I noticed that, if the option has space (Eg: Tom Hanks) it doesnt get saved. If its a single word like John there is no issue. when i try to echo this option(Tom Hanks) only Tom gets printed.

I am not able to figure the what is the issue? is it necessary to have a single word as option or is it issue with $_POST and i ve put it thru some function.

any help/suggestion most appreciated.

Thank you ppl of the forum..

Recommended Answers

The option tag needs a value.

Tom Hanks


Jump to Post

All 8 Replies

Show your html/php code that handles the dropdown. Perhaps you forgot some quotes.

change the code in html to send tom\ hanks
that should do the job i think

<form action="this.php" method="post">

<select name="actor" id="actor">
<option>Tom Hanks</option>
<input type="submit" name="btnSubmit" value="Submit" />
echo $a;

the code is like this, now if u select John it prints, but if u select Tom Hanks it wont.

The option tag needs a value.

<option value="Tom Hanks">Tom Hanks</option>

thanks pritaeas and anilashanbhag

guys, have a look at my code.

anilashanbhag, i tried what u mentioned that dint work, it pprints only tom :(

no i thought u have put the value already and still it didnt print

if it is solved then fine

else try value = "tom\ hanks" once

Simply do it the following way

<form method = "post">
<select name="actor">
<option value="John">John</option>
<option value="Tom">Tom Hanks</option>
<option value="Harry">Harry</option>
<input type="submit" name="btnSubmit" value="Submit" />

echo $_POST;

thanks all that worked fine, but when i tried to get the options of the dropdown from database, then tried to print, it doesnt happen again, the html code of dropdown is as follows

<select name="component" id="component" >

	while($rowComp = mysql_fetch_array($resComp))
	echo "<option id=".$rowComp['id']." value=".$rowComp['name'].">".$rowComp['name']."</option>";

is something wrong with this code? only 1st word of the option is printed.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.