Unable to get entire contents of combobox into variable

I have a combobox filled with menuitems from a mysql database. For eg. One of the menuitems is sweet and sour chicken. When i try to output the variable for combobox item on to another form only the first part of the variable is displayed eg. sweet. This is the case for all the items in the combobox. However the items themselves in the combobox appear correctly. How can i get the entire part of the item from the combobox. I used

$itemName = $_POST[“itemName”];

however,
on the form where the combobox is, i used $row[itemName]; to display the contents into the combobox.

if i understood correctly, the combobox you using is a multi select dropdown right?

if so you need get each selected value into a array like this

[php]
foreach($_POST[‘itemName’] as $x)
{
$arr[]= $x;
}
[/php]

$arr should contains all the selected value good luck i did not test this let me know if that worked

hi, i’m using a single select drop down box. to make it clear all i need is to retrieve the values in the drop down box as they are, however, say if i select an item in the list eg which is sweet and sour chicken, and sour chicken gets left off and the variable shows only sweet. This happens for all list items that are made up of more than one word. Am not sure why it’s doing this as there is no code that splits the items.

take a a look at the link below and tell which dropdown is the one you using?


http://foundworld.com/cis150/forms.html#dropdown

am using combo2 example however instead of a blank option. i have the option of “Select an option”.

Select an option

if you have
[php]

sweet and sour chicken [/php]

and you select ‘sweet and sour chicken’

php is given the value of ‘sweet’ because the selected value is ‘sweet’.

this is the code
[php] <?
if (!$db)
{
echo “Error: Could not connect to database. Please try again later.”;
exit;
}
mysql_select_db(“orders”);
$query = “select itemName from menuitems aesc “;
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
//$itemPrice = $row[“itemPrice”];
for($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
//echo htmlspecialchars( stripslashes($row[“tableNo”]));
echo “<option value=”.$row[“itemName”].” >”.$row[“itemName”]."";

	//echo "</p>";
}	echo "</select>";	
	
	?>[/php]

when i click on the submit button in the next form i need to access the itemName that was selected in the previous form.

show me the other form i will test it on my localhost

the second form is as below

Insert Order

Insert Order

<? $tableNo = $_POST["tableNo"]; $itemQty = $_POST["itemQty"]; $itemName = $_POST["itemName"]; $itemPrice = $_POST["itemPrice"]; echo" ".$tableNo." ".$itemQty." ".$itemName." ".$itemPrice." "; //|| !$itemPrice if(!$tableNo || !$itemQty || !$itemName ) { echo "You have not entered all the required details.
" ."Please go back and try again."; exit; }
$tableNo = addslashes($tableNo);
$itemQty = addslashes($itemQty);
$itemName = addslashes($itemName);
$itemPrice = doubleval($itemPrice);

@ $db = mysql_pconnect("localhost","root","administrator");

if (!$db)
{
	echo "Error: Could not connect to database. Please try again later.";
	exit;
}

mysql_select_db("orders");

$query = "insert into ordersreceived (tableNo, itemQty, itemName, itemPrice, totalPrice ) values ('".$tableNo."','".$itemQty."','".$itemName."','".$itemPrice."','".$itemQty*$itemPrice."')";
$result = mysql_query($query);
if ($result)
	echo mysql_affected_rows()." order inserted into database.";

?>

the problem above is with the $itemName. I get only part of a menu item from the previous form.

look for the following line of code replace it with
[php]
echo “”.$row[“itemName”]."";
[/php]

that should have fixed

good luck

which line should i look for

look for :
[php]
echo “<option value=”.$row[“itemName”].">".$row[“itemName”]."";
[/php]

replace with:
[php]
echo “”.$row[“itemName”]."";
[/php]

thanks wilson. this solved the issue. There is another post i could use your help with.

Sponsor our Newsletter | Privacy Policy | Terms of Service