php select box only saving first part of value

Hi All,

Something strange has happened to my code and all of a sudden my select dropdown is only saving the first part of the value to the database. for instance a dropdown will list all suppliers with their full name displayed i.e ‘COMPANY NAME LTD’ but when I select one and save to the database the script is also adding/updating the database with the value up until it hits a space with the name.

I’ve tried to search on the internet to see if anyone else has experienced this but couldn’t locate any topics?

my code is as follows;-

[php]<?php
$supplier = “SELECT name FROM fms_tbl_suppliers WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ ORDER BY name ASC”;
$result = mysqli_query ($db, $supplier);

echo “”;
echo “SELECT…”;

while($r = mysqli_fetch_array($result)){
echo “” . $r[‘name’] . “”;
}
echo “”;
?> [/php]

can any one shed any light or point me in the right direction?

Double check the field in the database hasn’t got a length. Failing that, at least show us the relevant insert/update code.

I agree with scott. The database is likely truncating the data, but, the database design is faulty.

[php]echo “” . $r[‘name’] . “”;[/php]

Should be,

[php]echo “” . $r[‘name’] . “”;[/php]

And that id links them to a specific supplier. Otherwise you are taking up more room than necessary.

thanks Astonecipher, I don’t think its the database itself causing the issue as i altered the value to 50 and it still didn’t make a difference.

This issue affects all of my select boxes across my site, when I use an input box all of the data is saved, it is only when I am using a select dropdown - and unfortunately I cannot live without these.

I understand your concept which is a better way, however I need to display the supplier name etc rather than the id on the order print out & reports. currently all I need to do is echo the database value. I would need to echo the id and then cross this with the supplier database to pull the name through.

my code to update these select box is:-
[php]


Supplier
<?php $supplier = "SELECT name FROM fms_tbl_suppliers WHERE client_id='{$_SESSION['client_id_of_user']}' ORDER BY name ASC"; $result = mysqli_query ($db, $supplier);

echo “”;
echo “” . $row[‘supplier’] . “”;

while($r = mysqli_fetch_array($result)){
echo “” . $r[‘name’] . “”;
}
echo “”;
?>

[/php]

so it displays the database saved value first with the option to then alter to another if need be.

How would I go about introducing another query within this (if this is my best option)?

You would use a join and pull all of the data for a given order. Kevin or I could help with the query itself.

So what your saying is, catch a buzz first…

Whatever makes your development team happy I guess!

thanks guys, I’ve sorted the issue out with the missing values. it obviously doesn’t fix the long term issue but I’d like to speak more on the coding for hire.

my code ending up being;-
[php]<?php
$supplier = “SELECT name FROM fms_tbl_suppliers WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ ORDER BY name ASC”;
$result = mysqli_query ($db, $supplier);

echo “”;
echo “SELECT…”;

while($r = mysqli_fetch_array($result)){

echo ‘’;
echo htmlspecialchars($r[‘name’]);
echo ‘’;

}
echo “”;
?> [/php]

I'd like to speak more on the coding for hire.

I am available. Just PM me.

Sponsor our Newsletter | Privacy Policy | Terms of Service