drop down list in php

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
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

drop down list in php

Post by nawhaley »

I've got a rather odd occurance in my php code thats causing me some issues. I used the following code to make my drop down list.

Code: Select all

function EditScreen()
{
$link = odbc_connect("database","username","password");
$qquery = "Select Question from tblQuestions";
$qresult = odbc_exec($link,$qquery);
print('<FORM METHOD = "POST" ACTION = "edit.php">');
print('<SELECT NAME="question">');
while(odbc_fetch_row($qresult))
{
 $question = odbc_result($qresult,"Question");
 print('<OPTION VALUE ='. "$question".'>'."$question");
}
print('</SELECT>');
print("<BR>");
print('<INPUT TYPE ="submit" NAME = "submit" VALUE ="EditQuestion">');
print('<INPUT TYPE ="submit" NAME = "submit" VALUE ="EditAnswer">');
print("<BR>");
print('</FORM>');
}
then go to the edit page to print the info from it out like so.

Code: Select all

session_start();
include 'maintfunctions.php';
switch($_POST['submit'])
{
case 'EditQuestion':
print $_POST['question'];  
  break;
default:
  break;
and all I get is the first word of the value chosen in the dropdown list :/. Does anyone have any ideas what may cause this odd occurance?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Your quotes have been escaped. Try using this

Code: Select all

print('<OPTION VALUE ="'. $question.'">'."$question");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your "value" attribute doesn't have quotes around the value itself....
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

thanks guys this is what comes from editing code in notepad instead of another editor very hard to see stuff like this thanks for the help!
Post Reply