Home > Archive > PHP SQL > April 2004 > Truncation on PHP query?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Truncation on PHP query?
|
|
| Adrian Parker 2004-04-29, 6:13 pm |
| 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)
| |
| Pierre Tremblay 2004-04-29, 6:13 pm |
| Hi Adrian!
Maybe have a look at function rtrim and ltrim in order to suppress any blank
that are not supposed to be there?
ex:
$query = "INSERT INTO students Values ('', '1', '" . $_POST["firstName"]
..
"', '
" . $_POST["lastName"] . "', '
" . $_POST["licenseNumber"] . "', '
" . $_POST["eMail"] . "', '
" . ltrim($_POST["phone"]) . "', '
" . $_POST["city"] . "', '
" . $_POST["address"] . "', '
" . $_POST["birthDate"] . "')";
"Adrian Parker" <adrian.parker@NOSPAMsympatico.ca> wrote in message
news:d1akc.41057$OU.957826@news20.bellglobal.com...
> 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 2004-04-29, 6:13 pm |
|
"Pierre Tremblay" <pierret@pierretci.com> wrote in message
news:Sfbkc.13647$k%.389215@news20.bellglobal.com...
> Hi Adrian!
>
> Maybe have a look at function rtrim and ltrim in order to suppress any
blank
> that are not supposed to be there?
>
> ex:
>
> $query = "INSERT INTO students Values ('', '1', '" .
$_POST["firstName"]
> .
> "', '
> " . $_POST["lastName"] . "', '
> " . $_POST["licenseNumber"] . "', '
> " . $_POST["eMail"] . "', '
> " . ltrim($_POST["phone"]) . "', '
> " . $_POST["city"] . "', '
> " . $_POST["address"] . "', '
> " . $_POST["birthDate"] . "')";
Why did one space before the phone number cut 4 digits off the number when
it was stored in the database (as text)?
You're right, your solution worked, I just don't understand it.
Why is: " 6135315960" == "613531"
Adrian
> "Adrian Parker" <adrian.parker@NOSPAMsympatico.ca> wrote in message
> news:d1akc.41057$OU.957826@news20.bellglobal.com...
> the
the[color=darkred]
$_POST["firstName"][color=darkred]
> .
database[color=darkred]
and[color=darkred]
>
>
|
|
|
|
|