...

View Full Version : strings returning only one word???



irenaught
07-31-2008, 08:09 AM
I am trying to put together an online stock and orders DB I need to return the name of an item which is selected by the user from an auto-populated select menu. I am using the following code

<form action="order_entry.php" method="post" name="order_entry" id="order_entry" >
<br/>Choose an item to add to the order.<br />
<select name="order_items" id="order_items"><br/>
</p>

<?php
$query = 'SELECT item_name FROM `items` ORDER BY item_name ';
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );

while($row=mysql_fetch_array($result)){

echo "<OPTION VALUE=".$row[item_name].">".$row[item_name]."</OPTION>";
}

?>

</select>
<p>
<br />Please enter the quantity<br />
<input name="quantity" type="text" id="quantity" size="40"/>
<input type="submit" id="submit" value="Add item to order" />
<input type="button" id="complete" value="All items are added" />
</p>
<?php
//connect to db

//include "../../scripts/basic_connect.php";
$quantity = mysql_real_escape_string($_REQUEST['quantity']);
$itemname = mysql_real_escape_string($_REQUEST['order_items']);

printf("The string contains: %s", $itemname);

$orderitemsql = "select item_id from items where item_name ='$itemname' ";
$itemqry = mysql_query($orderitemsql) or die ("Unable to Make the Query:" . mysql_error() );
$item = mysql_fetch_array($itemqry);

echo 'you have added'.' '."$quantity".' '.'copies of '.' '."$itemname";
echo '</br>';

?>


</form>

the output i get ($itemname) only contains the first word of the item title which is displayed in the select list. because of this the following SQL query fails to get the item_id field which is needed to update the other tables. Anyone have any ideas ? this is sort of a continuation of an earlier post entitled "help with php resource id" if anyone wants to see the whole code it is there. Thanks.

irenaught
07-31-2008, 11:33 AM
Ok I used a work around where i changed the names stored in the DB field item_name into underscored together strings so all the words are the first word. It works but I am still very curious to know why this was happening. Anyonw who can take a stab at it even if its just a guess that would be great. Just please tell me wether you know or if its a guess. This is the first thing I have ever coded so any help is awesome. Thanks again.

CFMaBiSmAd
07-31-2008, 03:01 PM
Your HTML for the value="..." parameter is missing the quotes around the value "your_value_here"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum