This is a discussion on Truncation on PHP/SQL query? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have the code below. It builds an INSERT command, and it gets run on the database. Everything works fine ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 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" <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 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. |