FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Why is my form field value truncated?





DoctorBeaver
php/mySQL.

This is really weird. I'm pulling a field from the database (a phone number) and displaying it in a form for editing. The field in the database is varchar(15). On the form size and maxlength are both 15.

However, for some reason only the area code is diplayed. The rest of the phone number is missing.

I've put a debug just above where the field is displayed and the whole number is there.

Here is the form field code:

Code:

      $this->debug_func($cont_phone);
      echo '<td valign="TOP">';
         echo 'Phone<br />';
         echo '<input type="text" name="contact_phone" id="contact_phone" size="15" maxlength="15" value='.$cont_phone.' />';
      echo '</td>';


This is the database call:

Code:

function get_contact_by_id($contact_id)
{
    $cont_array=NULL;
   $query="SELECT * FROM contact_details WHERE contact_id='$contact_id'";
    $result=mysql_query($query) or die(mysql_error());
    if (mysql_num_rows($result))
    {
      $cont_array=mysql_fetch_assoc($result);
      $this->current_contact=$contact_id;
   }
    
    return $cont_array;
}


And the bit in the code where I set the variable to be displayed = what I get from the database:

Code:

   $cont_name =$cont_array['contact_name'];
   $cont_phone=$cont_array['phone'];
   $cont_email=$cont_array['email'];


There is nowhere that I truncate the variable and the display field is exactly the right size.

Everywhere else I display a phone number they come up fine. It's just this 1 place.

Has anyone got any idea what the hell is going on?

UPDATE:

I changed the form field code to include double quotes around the variable name thus:

Code:

      $this->debug_func($cont_phone);
      echo '<td valign="TOP">';
         echo 'Phone<br />';
         echo '<input type="text" name="contact_phone" id="contact_phone" size="15" maxlength="15" value="'.$cont_phone.'" />';
      echo '</td>';


and now it works fine.

Why would leaving the double quotes out truncate the field?
Peterssidan
DoctorBeaver wrote:
Why would leaving the double quotes out truncate the field?

If you use space characters in the phone number it will look like you try to write another attribute or something.
Code:
... value=123 456 />
Best to always use double quotes to be safe. I think the standard say that you should always use double quotes these days anyway.
DoctorBeaver
Ah, thank you Peterssidan. That would explain it. I never thought of that.
Related topics
HTML + PHP problem
Java tutorials
problem adding variables in javascript
Create a Simple form
black hole??
Getting Hebrew User Input...
Javascript function not working!!??
question about mail a friend script
Need help fixing my php file
[OK] How to force the filling of a email form field ?
Desperately Seeking Help!
Posting Data to multiple sites at once?
Philosophy Essays & Philosophy Texts
Looking for a javascript input validator (name your price)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.