Ask a Question related to PHP Development, Design and Development.
-
Adrian Parker #1
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
-
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. ... -
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... -
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... -
[PHP] magical file writing truncation
$newFile = "xml/".$type."/".$now.".xml"; while(file_exists($newFile)) $newFile = "xml/".$type."/".$now++.".xml"; $text = $_POST; $text =... -
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... -
Colin McKinnon #2
Re: Truncation on PHP/SQL query?
Adrian Parker spilled the following:
Looks OK, and you've checked the things I would have checked...> 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', ' ', ' ', ' ')
>
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
-
Adrian Parker #3
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...There is a single space before the phone number. When I remove it,> 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.
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
-
Colin McKinnon #4
Re: Truncation on PHP/SQL query?
Adrian Parker spilled the following:
When I cut & paste your code I get:>
> <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.
>
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



Reply With Quote

