Select box value is stoping at space

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
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Select box value is stoping at space

Post by dimxasnewfrozen »

I have no idea why this is happening but when I select a select box value from the box , the value that gets stored in the post variable stops at the space.

This select box:

Code: Select all

$d = "SELECT * FROM DEPARTMENTS";
$p = ociparse($cisConnection, $d);
ociexecute($p);
$d_nr = ocifetchstatement($p, $d_results);
	echo "<select id=\"forward_to\" name=\"forward_to\">";
		for ($d2=0; $d2 < $d_nr; $d2++ ){
			$department = $d_results['DEPARTMENT'][$d2];
			echo "<option style='padding:1px;' value=".$department.">" . $department ."</option>";
		}
      echo "</select>";
The select box is getting generated properly but when I submit the page for a selected value of "Human Resources"...
The $_POST['forward_to'] variable would be "Human ".
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: Select box value is stoping at space

Post by dimxasnewfrozen »

Gah I got it...

Code: Select all

echo "<option style='padding:1px;' value= \"$department\">" . $department ."</option>";
instead of:

Code: Select all

echo "<option style='padding:1px;' value= ".$department.">" . $department ."</option>";
phu
Forum Commoner
Posts: 61
Joined: Tue Mar 30, 2010 6:18 pm

Re: Select box value is stoping at space

Post by phu »

You might want to consider separating your HTML from your PHP more clearly. A project larger than a single page can get very difficult to read and debug very quickly with the presentation and logic mixed up like this.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Select box value is stoping at space

Post by Jonah Bron »

Please edit your original post, and put [SOLVED] into the subject.
Post Reply