Truncation on PHP/SQL query?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Truncation on PHP/SQL query?

    I have the code below. It builds an INSERT command, and it gets run on the
    database. Everything works fine except the database is only receiving the
    first 6 characters of the phone number.

    The field in the database can hold 10 digits (confirmed). The echo
    statement shows that the phone number is indeed 10 characters long.

    The second echo statement show the $query looks similar too:
    INSERT INTO students Values ('', '1', 'SomeFirstname', 'SomeLastName',
    'License', 'adrian.parker@sympatico.ca', ' 6135315960', ' ', ' ', ' ')

    When I run this query in mySQL when logged onto the terminal, the phone
    number appears fine.

    How could truncation be happening?


    if (isset($_POST["firstName"]))
    {
    $query = "INSERT INTO students Values ('', '1', '" . $_POST["firstName"] .
    "', '
    " . $_POST["lastName"] . "', '
    " . $_POST["licenseNumber"] . "', '
    " . $_POST["eMail"] . "', '
    " . $_POST["phone"] . "', '
    " . $_POST["city"] . "', '
    " . $_POST["address"] . "', '
    " . $_POST["birthDate"] . "')";

    echo "Phone number is: " . $_POST["phone"] . "<br><br>";
    echo "The query statement is: " . $query . "<br>";

    $result = mysql_query($query) or die("Adding the student to the database
    failed: " . mysql_error());
    }



    <Ade
    --
    Adrian Parker. Ordained priest. <adrian.parker@sympatico.ca>

    "A society that views graphic violence as entertainment ...should not be
    surprised when senseless violence shatters the dreams of it's youngest and
    brightest..." - Ensign (March 2004)


    Adrian Parker Guest

  2. Similar Questions and Discussions

    1. Oracle CLOB Truncation > 64K
      We have an update and insert query for a large text field (Oracle CLOB). When we run the query on long text, it truncates the excess. ...
    2. Data Truncation error
      Hello, I have CF MX 7, developer version Database is MySQL v. 4.1.12 Every 15 days I receive new ASCII files which contains data which have to...
    3. Data truncation in SELECT
      Hi all. I'm executing a simple SELECT statement to return the value that's been stored as a LONGTEXT in a mySQL db. The code to insert the data...
    4. [PHP] magical file writing truncation
      $newFile = "xml/".$type."/".$now.".xml"; while(file_exists($newFile)) $newFile = "xml/".$type."/".$now++.".xml"; $text = $_POST; $text =...
    5. TextStream Line Truncation
      In an ASP page, I am using the FileSystemObject OpenTextFile method to initiate a TextStream object. In some files I have long lines and it...
  3. #2

    Default Re: Truncation on PHP/SQL query?

    Adrian Parker spilled the following:
    > Everything works fine except the database is only receiving the
    > first 6 characters of the phone number.
    >
    > The field in the database can hold 10 digits (confirmed). The echo
    > statement shows that the phone number is indeed 10 characters long.
    >
    > The second echo statement show the $query looks similar too:
    > INSERT INTO students Values ('', '1', 'SomeFirstname', 'SomeLastName',
    > 'License', 'adrian.parker@sympatico.ca', ' 6135315960', ' ', ' ', ' ')
    >
    Looks OK, and you've checked the things I would have checked...

    Maybe there's some whitespace you're not (won't) seeing in your browser -
    try viewing the source or generating the SQL statement as a single line.

    HTH

    C.

    Colin McKinnon Guest

  4. #3

    Default Re: Truncation on PHP/SQL query?


    "Colin McKinnon"
    <colin.thisisnotmysurname@ntlworld.deletemeunlessU RaBot.com> wrote in
    message news:02fkc.211$xt3.41@newsfe1-gui.server.ntli.net...
    > Adrian Parker spilled the following:
    >
    > > Everything works fine except the database is only receiving the
    > > first 6 characters of the phone number.
    > >
    > > The field in the database can hold 10 digits (confirmed). The echo
    > > statement shows that the phone number is indeed 10 characters long.
    > >
    > > The second echo statement show the $query looks similar too:
    > > INSERT INTO students Values ('', '1', 'SomeFirstname', 'SomeLastName',
    > > 'License', 'adrian.parker@sympatico.ca', ' 6135315960', ' ', ' ', ' ')
    > >
    >
    > Looks OK, and you've checked the things I would have checked...
    >
    > Maybe there's some whitespace you're not (won't) seeing in your browser -
    > try viewing the source or generating the SQL statement as a single line.
    There is a single space before the phone number. When I remove it,
    everything is ok.

    I don't understand why a space at the beginning chomps off 4 bytes at the
    end of the string.


    Adrian


    Adrian Parker Guest

  5. #4

    Default Re: Truncation on PHP/SQL query?

    Adrian Parker spilled the following:
    >
    > <colin.thisisnotmysurname@ntlworld.deletemeunlessU RaBot.com> wrote in
    > message news:02fkc.211$xt3.41@newsfe1-gui.server.ntli.net...
    >> Maybe there's some whitespace you're not (won't) seeing in your browser -
    >> try viewing the source or generating the SQL statement as a single line.
    >
    > There is a single space before the phone number. When I remove it,
    > everything is ok.
    >
    > I don't understand why a space at the beginning chomps off 4 bytes at the
    > end of the string.
    >
    When I cut & paste your code I get:

    00000c0: a0a0 a022 a02e a024 5f50 4f53 545b 2265 ..."...$_POST["e
    00000d0: 4d61 696c 225d a02e a022 272c a027 0aa0 Mail"]..."',.'..
    00000e0: a0a0 22a0 2ea0 245f 504f 5354 5b22 7068 .."...$_POST["ph
    00000f0: 6f6e 6522 5da0 2ea0 2227 2ca0 270a a0a0 one"]..."',.'...
    0000100: a022 a02e a024 5f50 4f53 545b 2263 6974 ."...$_POST["cit
    0000110: 7922 5da0 2ea0 2227 2ca0 270a a0a0 a022 y"]..."',.'...."
    0000120: a02e a024 5f50 4f53 545b 2261 6464 7265 ...$_POST["addre

    i.e. your spaces turned into a0 chars. There are also other unprintable
    characters in there. If this is your source then its probably changing
    charsets at least twice before it hits the db. Loose the whitespace.

    You might want to check your source code with xxd to see what you're really
    typing.

    C.
    Colin McKinnon Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139