Page 1 of 1

drop down list in php

Posted: Tue Aug 16, 2005 9:40 am
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?

Posted: Tue Aug 16, 2005 9:45 am
by John Cartwright
Your quotes have been escaped. Try using this

Code: Select all

print('<OPTION VALUE ="'. $question.'">'."$question");

Posted: Tue Aug 16, 2005 9:46 am
by feyd
your "value" attribute doesn't have quotes around the value itself....

Posted: Tue Aug 16, 2005 10:03 am
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!