473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP INSERT Bad data

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', 'a************@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. <ad***********@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)
Jul 17 '05 #1
4 1531
In article <_0*******************@news20.bellglobal.com>,
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote:
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', 'a************@sympatico.ca', ' 6135315960', ' ', ' ', ' ')


I would guess the space between the first ' and the 6 is messing things
up. I don't know how the phone number column in your database is
defined, but could there be some silent character-to-number conversion
going on here, with unwanted results? Try it without that first space
and see what happens.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

"Jan Pieter Kunst" <de*****@cauce.org> wrote in message
news:de***************************@news1.news.xs4a ll.nl...
In article <_0*******************@news20.bellglobal.com>,
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote:
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', 'a************@sympatico.ca', ' 6135315960', ' ', ' ', ' ')


I would guess the space between the first ' and the 6 is messing things
up. I don't know how the phone number column in your database is
defined, but could there be some silent character-to-number conversion
going on here, with unwanted results? Try it without that first space
and see what happens.


It's being stuffed into a string, so there should be no problem. There is
no middleware between the database and my script, so there should be nothing
altering the data.

.... ok, removed the leading space, it fixed it!

Why would a leading space cause problems when inserting into a text field?
Adrian
Jul 17 '05 #3
On Thu, 29 Apr 2004 18:52:57 +0200
Jan Pieter Kunst <de*****@cauce.org> wrote:
In article <_0*******************@news20.bellglobal.com>,
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote:
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', 'a************@sympatico.ca', '
6135315960', ' ', ' ', ' ')


I would guess the space between the first ' and the 6 is messing
things up. I don't know how the phone number column in your database
is defined, but could there be some silent character-to-number
conversion going on here, with unwanted results? Try it without that
first space and see what happens.


If the field is INT the space won't matter, but an INT is 4 bytes. It
lets you store x such that -2147483648 < x < 2147483647. If it's INT,
then it won't fit. If it's varchar(10), then '6135315960' will, but
a string such as ' 6135315960' won't.
Jul 17 '05 #4

"Kelly Thompson" <kt*************@hotmail.com> wrote in message
news:20040429150809.6abd4f7a.kt*************@hotma il.com...
On Thu, 29 Apr 2004 18:52:57 +0200
Jan Pieter Kunst <de*****@cauce.org> wrote:
In article <_0*******************@news20.bellglobal.com>,
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote:
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', 'a************@sympatico.ca', '
6135315960', ' ', ' ', ' ')


I would guess the space between the first ' and the 6 is messing
things up. I don't know how the phone number column in your database
is defined, but could there be some silent character-to-number
conversion going on here, with unwanted results? Try it without that
first space and see what happens.


If the field is INT the space won't matter, but an INT is 4 bytes. It
lets you store x such that -2147483648 < x < 2147483647. If it's INT,
then it won't fit. If it's varchar(10), then '6135315960' will, but
a string such as ' 6135315960' won't.


It's a Varchar(10) field.

Why again does the leading space remove 4 bytes from the end of the string?
Adrian
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
4
by: authorking | last post by:
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be...
2
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
2
by: wombat53 | last post by:
Hi Group Are there any DB2 UDB ESE DPF V8.2 users exploiting "buffered inserts" (BIND parm INSERT BUF) *and* "multi-row INSERTS" (many rows associated with the VALUES clause of the INSERT to...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.