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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Form - Post method data/variable truncated

    I have a php page with a drop down list - however on submitting the data gets truncated.
    217 2009 shows only 217 in the receiving php page
    The the mysql field is char(50) value 217 2009
    if this is changed to to 2172009 it passes correctly to the next php page.
    obviously the blank in between is the reason for truncation.
    Can't change the field to text as phpMyAdmin protests
    "#1170 - BLOB/TEXT column 'RegNo' used in key specification without a key length " changing to text may have been an option
    is there a way to programatically pass this value correctly?

    All help will be received gratefully.
    Last edited by AS Randy; 12-17-2010 at 09:05 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    is there a way to programatically pass this value correctly?
    Is that value Okay in the POST data? Please show your code
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    the code

    Thank you for replying the code is below;-
    <?php
    mysql_connect('localhost', 'xxxx', 'xxxxxx');
    mysql_select_db('dg2c');
    $result = mysql_query('select * from socs');

    $query="SELECT RegNo, Unit , Nomenclature FROM socs";

    /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */

    $result = mysql_query ($query);
    echo "<form name='form' method='post' action='form1.php'>";
    echo "<select name='search' value=''></option>";// printing the list box select command

    while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
    echo "<option value=$nt[RegNo]>$nt[RegNo] ::$nt[Unit]:: $nt[Nomenclature]</option>";
    /* Option values are added by looping through the array */
    }

    echo "</select>\n";// Closing of list box

    echo "<input type='submit' name='submit' value='Submit'>";
    echo "</form>";

    ?>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Your value on the option doesn't have any quotations around it. It has no idea what you are trying to use, so it assumes the next 'word' is what you want. As soon as you hit the space, it assumes that the 2009 is a new property attribute, and not a value associated with... value. Lol.
    PHP Code:
    printf('<option value="%s">%s ::%s:: %s</option>' PHP_EOL$nt['RegNo'], $nt['RegNo'], $nt['Unit'], $nt['Nomenclature']); 
    try that for your option printout and see if that works.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Your value on the option doesn't have any quotations around it. It has no idea what you are trying to use, so it assumes the next 'word' is what you want. As soon as you hit the space, it assumes that the 2009 is a new property attribute, and not a value associated with... value. Lol.
    PHP Code:
    printf('<option value="%s">%s ::%s:: %s</option>' PHP_EOL$nt['RegNo'], $nt['RegNo'], $nt['Unit'], $nt['Nomenclature']); 
    try that for your option printout and see if that works.
    will do
    actually had been reading on that and this is how it should have been
    echo "<option value="".$nt[RegNo]."">".$nt[RegNo]."</option>";

    but somehow does not work in the while statement.

  • #6
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked - crazeee. My case is I am learning php mysql by jumping into the deep end, guess can't do without basics.
    Thanks - will have to decipher all that code in your example.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    echo "<option value="".$nt[RegNo]."">".$nt[RegNo]."</option>"
    That one doesn't work since PHP doesn't understand what you are doing with the quotations. It considers the output as "<option value=" and then tries to parse ".$nt[RegNo]."..... as PHP and will fail (" is an invalid identifier token). What would work is:
    PHP Code:
    echo '<option value="'.$nt[RegNo].'">'.$nt[RegNo].'</option>';
    // Or
    echo "<option value=\"".$nt[RegNo]."\">".$nt[RegNo]."</option>"
    On a side note, arrays with string indicies should be treated as strings: $nt['RegNo'] is correct while $nt[RegNo] is not. If you enable your error reporting, it will indicate that RegNo is an invalid constant and it assumed you meant 'RegNo' (as a string).

    I'm a print formatter. printf simply takes a parsable string and the corresponding variables.
    '<option value="%s">%s ::%s:: %s</option>' indicates I want that string output, but to replace 4 variables treated as strings (%s). I then provide it with the 4 variables to parse as strings and replace into the output.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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