Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    strings returning only one word???

    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.

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,147
    Thanks
    2
    Thanked 333 Times in 325 Posts
    Your HTML for the value="..." parameter is missing the quotes around the value "your_value_here"
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •