Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with scroll-down list and PHP


Problem with scroll-down list and PHP

Reply
  #1 (permalink)  
Old 11-24-11, 07:59 AM
Silverjoker Silverjoker is offline
New Member
 
Join Date: Nov 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Problem with scroll-down list and PHP

Hi, I'm writing a form to allow people to add entries to a mysql database table of used books.

I'm using the following code to populate scroll-down lists from the database for some fields of the form:

Code:
<?php
$Qauthor="SELECT DISTINCT author FROM booklist ORDER BY author ASC";
$author=mysql_query($Qauthor);
echo "Author: <select name=author value=''></option>";
while($ar=mysql_fetch_array($author))
{
echo "<option value=$ar[author]>$ar[author]</option>";
}
echo "</select>";
?>
This works well, except for one problem. The author names in the mysql table are written in the following way: Lastname, Firstname
The names on the list are shown correctly, but when I try to fetch the data from the form to update the database, everything after the comma (mostly the first name, but sometimes also the middle name) does not show.
I tested it using simply
Code:
echo $_POST['author']
it shows only the following: Lastname,

It's my first time using PHP and I'm at a loss to what I should do to fix this. Is the problem with how the scroll-down list is generated?
Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 11-25-11, 02:09 AM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
not sure how your database is structured but im guessing with a small modification to the query i might work... try
Code:
$Qauthor="SELECT author FROM group by author booklist ORDER BY author ASC";
Reply With Quote
  #3 (permalink)  
Old 11-25-11, 10:09 AM
Silverjoker Silverjoker is offline
New Member
 
Join Date: Nov 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
The table is sorted by an AUTO_INCREMENT id number, the other columns are just different information about the books (eg. title, author, etc). The full author name is in one column: "Grigorieff, Vladimir" without quotes.

After a few more tests, I realized the problem was not with my query, as posting the query by itself worked well. Also the names are complete when selecting from the list.

The problem is when I try to use the input data from a <select> list, using $_POST['author']. Where it should read "Grigorieff, Vladimir", we only see "Grigorieff,".
In fact, any data after a blankspace doesn't show.

I hope there is a way around that, because the table is quite big.
Reply With Quote
  #4 (permalink)  
Old 11-25-11, 03:01 PM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
see the select tag? theres something very wrong about it... change it to
echo 'Author: <select name="author">'; and leave the rest as it is.

edit:
oooo shiiiii.... a lot more than that is wrong...

Code:
echo '<option value="'.$ar['author'].'">'.$ar['author'].'</option>';

Last edited by alxkls; 11-25-11 at 03:04 PM.
Reply With Quote
The Following User Says Thank You to alxkls For This Useful Post:
Silverjoker (11-25-11)
  #5 (permalink)  
Old 11-25-11, 03:53 PM
Silverjoker Silverjoker is offline
New Member
 
Join Date: Nov 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
It worked. I had used a code shown by someone on a forum, and didn't realize it was this messed up.

Thanks a lot!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wordpress PHP problem... jackster PHP 3 07-06-08 10:51 PM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 08:26 AM
PHP Drop down list Using Oracle RatherSurf PHP 2 02-23-05 01:18 PM
Create List with PHP ...? demnos PHP 6 08-13-04 02:40 PM
Database table contents to email problem (PHP and MySQL) blokeofftheinternet PHP 2 04-29-04 09:34 AM


All times are GMT -5. The time now is 08:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.