...

View Full Version : PHP Form - Post method data/variable truncated



AS Randy
12-17-2010, 09:03 AM
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.

abduraooft
12-17-2010, 09:54 AM
is there a way to programatically pass this value correctly?Is that value Okay in the POST data? Please show your code

AS Randy
12-18-2010, 04:24 PM
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>";

?>

Fou-Lu
12-18-2010, 04:38 PM
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.


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.

AS Randy
12-18-2010, 05:03 PM
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.


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.

AS Randy
12-18-2010, 05:12 PM
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.

Fou-Lu
12-18-2010, 06:16 PM
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:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum