Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown list only half transfering into database 1

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I have this form that contains about 13 fields.
Whn I hit submit all the information is transfered in a MySQL database.

I am having a small problem!!!!!!!!!!!!!!!
3 of the fields are dropdown lists.
Only some of the information from the dropdown lists is being transfered into the database. All the other fields are transfering over as expected.
For example, one of the lists contains names. If I select Michael Mouse, then only Michael is transfered across. It is only transfering the information up to the 'space' character.

Can anyone give me any clues

Thanking you in advance for any help received.

 
Are you putting quotes around your values in your option tags? ______________________________________________________________________
TANSTAAFL!
 
This is the relevent code I am using.
As I said before, the dropdown list works perfectly.
I can manually type the name into the MySQL Database.


<html>
<body>
<form method=&quot;post&quot; action=&quot;<?php
$db = mysql_connect(&quot;server&quot;, &quot;root&quot;, &quot;&quot;) or die;
mysql_select_db(&quot;names&quot;,$db) or die;
$sql='SELECT Entered_By FROM enteredby';
$result = mysql_query($sql,$db);
echo &quot;<select name=entered_by>&quot;;
while ($row = mysql_fetch_array($result)) {
echo &quot;<option value=$row[0]>$row[0]</option>\n&quot;;
}
echo &quot;</select>\n&quot;;
?>
<input type=&quot;Submit&quot; name=&quot;submit&quot;>
</form>

<?php

if(isset($_POST[submit])){

$db = mysql_connect(&quot;server&quot;, &quot;root&quot;);

mysql_select_db(&quot;input&quot;,$db);

$sql1 = &quot;INSERT INTO information (Entered_By) VALUES ('$_POST[entered_by]')&quot;;

$result1 = mysql_query($sql1);

echo &quot;Thank you! Information entered.\n&quot;;
}
?>
</body>
</html>
 
back to sleipnir's question? are you putting quotes arund the values in the option box? ANSWER : NO....

change the option echo statement to this:

echo &quot;<option value=\'&quot;.$row[0].&quot;\'>$row[0]</option>&quot;;

the '\n' is not needed as options automatically are displayed on the next line...

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Thank you Bastien.

likelylad, in the fora you can help yourself a lot by answering questions as well as asking them. ______________________________________________________________________
TANSTAAFL!
 
Hi sleipnir/Bastien

Thanks for getting back to me.
Yes you were correct in guessing that there were no quotes in the values in the options box.

Bastien, I had to tweak the code you supplied a minor bit to get it to work. Please see below

echo &quot;<option value='$row[0]'>$row[0]</option>&quot;;

Thanks very much for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top