Odd MySQL Problem...
am 14.10.2011 04:53:46 von Jason Pruim
--Apple-Mail-11-951209973
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
Hey everyone,
Have a weird issue that I can't seem to figure out...
Using PHP to insert phone numbers into the site... I have the Area Code, =
& Exchange, and then dynamically create the last 4 digits... Once it's =
inserted it's dropping the leading zero's... Here's some samples:
Copied from phpMySQL:
Edit Inline Edit Copy Delete 212 200 0 =
6800001
Edit Inline Edit Copy Delete 212 200 1 =
6800002
Edit Inline Edit Copy Delete 212 200 2 =
6800003
Edit Inline Edit Copy Delete 212 200 3 =
6800004
Edit Inline Edit Copy Delete 212 200 4
echoed output from PHP:
SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, =
200, 0001)=20
SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, =
200, 0002)=20
Actual PHP code:
// ini_set('display_errors', 1);
//error_log(-1);
set_time_limit(0);
//set_time_limit("120");
include "includes.php";
include "databaseabstraction.php";
include "authentication.php";
dbconnect("localhost", "XXXXXX", "XXXXXX", "XXXXXX")or die("Unable to =
connect: " . mysql_error());
function number_pad($number,$n) {
return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}
if (($handle =3D fopen("newyorktest.csv", "r")) !== FALSE) {
while (($data =3D fgetcsv($handle, 1000, ",")) !== FALSE) {
print_r($data);
foreach( range(0, 9999) AS $n) {
//echo "
DATA: " . $data[2] . "
";
$padded_number =3D number_pad($n, "4");
$sql =3D "INSERT INTO phonesite (areacode, exchange, =
subscriber) ";
$sql .=3D "VALUES({$data[1]}, {$data[2]}, {$padded_number}) =
";
//mysql_query($sql) or die("Didn't insert you dumb ass.... =
FIX IT NOW CLOWN!!!! " . mysql_error());
echo "SQL: " . $sql . "
";
}
}
echo "File Bitches!";
fclose($handle);
}
?>
Any ideas on what I'm missing?
Thanks everyone!
Jason Pruim
lists@pruimphotography.com
--Apple-Mail-11-951209973
Content-Type: multipart/related;
type="text/html";
boundary=Apple-Mail-12-951209973
--Apple-Mail-12-951209973
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=us-ascii
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey =
class=3D"Apple-style-span" face=3D"Times">
<?PHP
// =
ini_set('display_errors', =
1);
//error_log(-1);
set_time_limit(0);
=
//set_time_limit("120");
include =
"includes.php";
include =
"databaseabstraction.php";
include =
"authentication.php";
dbconnect("localhost", =
"XXXXXX", "XXXXXX", "XXXXXX")or die("Unable to connect: " . =
mysql_error());
function =
number_pad($number,$n) {
return str_pad((int) =
$number,$n,"0",STR_PAD_LEFT);
}
if =
(($handle =3D fopen("newyorktest.csv", "r")) !== FALSE) =
{
while (($data =3D fgetcsv($handle, 1000, =
",")) !== FALSE) =
{
print_r($data);
=
foreach( range(0, 9999) AS $n) {
=
//echo "<BR>DATA: " . $data[2] . =
"<BR>";
=
$padded_number =3D number_pad($n, "4");
=
$sql =3D "INSERT INTO phonesite (areacode, =
exchange, subscriber) ";
=
$sql .=3D "VALUES({$data[1]}, {$data[2]}, =
{$padded_number}) ";
=
//mysql_query($sql) or die("Didn't insert you dumb ass.... FIX IT =
NOW CLOWN!!!! " . mysql_error());
echo "SQL: " . $sql . =
"<BR>";
=
}
=
}
echo "File =
Bitches!";
=
fclose($handle);
}
>
class=3D"Apple-style-span" face=3D"Times">
color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; =
font-variant: normal; font-weight: normal; letter-spacing: normal; =
line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =
0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; font-size: medium; ">
Jason =
Pruim
href=3D"mailto:lists@pruimphotography.com">lists@pruimphotog raphy.com<=
/div>
=
--Apple-Mail-12-951209973
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=b_edit.png
Content-Type: image/png;
name="b_edit.png"
Content-Id: <4EC5ED54-41B1-44D2-B94C-3161D481782A@Pride>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/I NwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADAUExURf///+S6L96k NZhjILqLO8KCMdKd
L9uqT8uTU8mQT8qTUFhAE1lCEl5CFZNtHpxpJapgFrR2LLV9NLmJJr+QJ8GL SMJnFcOZMceDNMiQ
TsipZ8mRT8qVQs+cStCdWdScXdilatmPO9moUNzEbd2rc92ubOHLsOS6L+a0 XeiYQOyqYezPqfLh
yPLmvvPPb/TPpfTUp/TWRPXPpvXZaPXcYPfbvffhyfjhxfjiqPjjy/jtw/nj y/njzPrn0frujvz0
sywdqF4AAAALdFJOUwAJGSCtrt/q9/398YDkqQAAAGtJREFUGJVjYMANGNm5 JNmYkASUFMwsZVgR
fHUDcxsbU04E38pCVV/flAPBtzfWk1ORRuKbGNppKOLii6DxhXVR+MzCalIo 8nw6tkLiyrIScAfw
WWtpigkIIlzII2+kLYrEZ+Dm5RdkweNnADOjDvQ6wh73AAAAAElFTkSuQmCC
--Apple-Mail-12-951209973
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=b_inline_edit.png
Content-Type: image/png;
name="b_inline_edit.png"
Content-Id: <6C3C62C9-2973-4BC5-BD15-CDD559F3F771@Pride>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/I NwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAH8SURBVDjLjZPfS1Nh GMdXf0VEQhDUhdCN
4X0IYT8ghIJQM0KoC4vushZddLELKyRhQQkSFIKEGEkUCI2oxVhepG5zi1xb c0u3cDs7Z+ec/ezT
+x62scmmHvhwDrzP93Pe57znsQE2cR0SdAm6d+GwYL/M1LBVBV35fF4plUqV crlMK8Q6TqdzYruk
JuiW4Vwuh67rdbLZLJlMhmQyaUnigVlC05f4+dbB0tQplp92DsnwPimQBaZp UigUrLtE0zQURSGV
SqHF37DhGkVZeQdagszKLJ7HvZtNAhmuIQWGYaCqKps/ZkivPqCwPs/Gp0cY vjnKUTe+F9fMJoFo
o96zfJZ9K+sLpP33qRhujPANtr7dJPhqmO/PBxX3+PljTYLtqImPpH13qZge 9LUrmLEB1FU7sZd9
jJw5MljNthYk/KLnxdFqeAjzdz9Z/z3Ck2fRE36qx9pakAjME1y4Lbb9GTMy TD52GUXsZO3ZadTk
L6umrSD4ZZrAezvLH54Q915EjwywtXSH8FQf+t+I9V12FLwe6wE1SmjyAi77 Qb6Kt3rGe9H+hKzw
rgLH9eMUPE4K3gm8jpPMjRwlHfNTLBbr7Cjo7znA2NVOXA/PsThzi2wyah1p I+0E/9rNQQsqMtM4
CyfE36fLhb2ERa0mB7BR0CElexjnGnL0O2T2PyFunSz8jchwAAAAAElFTkSu QmCC
--Apple-Mail-12-951209973
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=b_insrow.png
Content-Type: image/png;
name="b_insrow.png"
Content-Id: <57637D51-3059-4322-A083-2326E0AA955D@Pride>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAABGdBTUEAAK/I NwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAPUExURf/MMzMzM8zM zGZmzAAAANwpnsUA
AAAFdFJOU/////8A+7YOUwAAAEpJREFUCFs9jcENwDAMAnl0AUuZwO0GzgJO bv+Z+khsXggdIK6U
ZgM2Wu4DYmq5f5XMy7zHQEzShtgRkXpElOmkmG71zlmmvvodfng4GisHj5mv AAAAAElFTkSuQmCC
--Apple-Mail-12-951209973
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=b_drop.png
Content-Type: image/png;
name="b_drop.png"
Content-Id: <273C015E-AED0-468E-9394-380D31270993@Pride>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/I NwWK6QAAABl0RVh0
U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJdSURBVDjLpZP7S1Nh GMf9W7YfogSJboSE
UVCY8zJ31trcps6zTI9bLGJpjp1hmkGNxVz4Q6ildtXKXzJNbJRaRmrXoeWx 8tJOTWptnrNryre5
YCYuI3rh+8vL+/m8PA/PkwIg5X+y5mJWrxfOUBXm91QZM6UluUmthntHqplx Uml2lciF6wrmdHri
I0Wx3xw2hAediLwZRWRkCPzdDswaSvGqkGCfq8VEUsEyPF1O8Qu3O7A09RbR vjuIttsRbT6HHzeb
sDjcB4/JgFFlNv9MnkmsEszodIIY7Oaut2OJcSF68Qx8dgv8tmqEL1gQaaAR tp5A+N4NzB0lMXxo
n/uxbI8gIYjB9HytGYuusfiPIQcN71kjgnW6VeFOkgh3XcHLvAwMSDPohOAD dYQJdF1FtLMZPmsl
vhZJk2ahkgRvq4HHUoWHRDqTEDDl2mDkfheiDgt8pw340/EocuClCuFvboQz b0cwIZgki4KhzlaE
6w0InipbVzBfqoK/qRH94i0rgokSFeO11iBkp8EdV8cfJo0yD75aE2ZNRvSJ 0lZKcBXLaUYmQrCz
DT6tDN5SyRqYlWeDLZAg0H4JQ+Jt6M3atNLE10VSwQsN4Z6r0CBwqzXesHmV +BeoyAUri8EyMfi2
FowXS5dhd7doo2DVII0V5BAjigP89GEVAtda8b2ehodU4rNaAW+dGfzlFkyo 89GTlcrHYCLpKD+V
7yeeHNzLjkp24Uu1Ed6G8/F8qjqGRzlbl2H2dzjpMg1KdwsHxOlmJ7GTeZC/ nesXbeZ6c9OYnuxU
c3fmBuFft/Ff8xMd0s65SXIb/gAAAABJRU5ErkJggg==
--Apple-Mail-12-951209973--
--Apple-Mail-11-951209973--
Re: Odd MySQL Problem...
am 14.10.2011 06:09:22 von Karl DeSaulniers
--Apple-Mail-1-955746280
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
Its looking for an integer not a string for the number of characters.
I think..
Eg : number_pad($n, 4);
On Oct 13, 2011, at 9:53 PM, Jason Pruim wrote:
> number_pad($n, "4");
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-1-955746280--
Re: Odd MySQL Problem...
am 14.10.2011 09:36:47 von David Robley
Jason Pruim wrote:
> Hey everyone,
>
> Have a weird issue that I can't seem to figure out...
>
> Using PHP to insert phone numbers into the site... I have the Area Code, &
> Exchange, and then dynamically create the last 4 digits... Once it's
> inserted it's dropping the leading zero's... Here's some samples:
>
> Copied from phpMySQL:
>
>
> Edit Inline Edit Copy Delete 212 200 0 6800001
> Edit Inline Edit Copy Delete 212 200 1 6800002
> Edit Inline Edit Copy Delete 212 200 2 6800003
> Edit Inline Edit Copy Delete 212 200 3 6800004
> Edit Inline Edit Copy Delete 212 200 4
>
>
> echoed output from PHP:
>
> SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212,
> 200, 0001) SQL: INSERT INTO phonesite (areacode, exchange, subscriber)
> VALUES(212, 200, 0002)
>
>
> Actual PHP code:
>
>
> // ini_set('display_errors', 1);
> //error_log(-1);
> set_time_limit(0);
>
> //set_time_limit("120");
> include "includes.php";
> include "databaseabstraction.php";
> include "authentication.php";
>
> dbconnect("localhost", "XXXXXX", "XXXXXX", "XXXXXX")or die("Unable to
> connect: " . mysql_error());
>
>
> function number_pad($number,$n) {
> return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
> }
>
> if (($handle = fopen("newyorktest.csv", "r")) !== FALSE) {
> while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
> print_r($data);
>
> foreach( range(0, 9999) AS $n) {
> //echo "
DATA: " . $data[2] . "
";
> $padded_number = number_pad($n, "4");
> $sql = "INSERT INTO phonesite (areacode, exchange,
> subscriber) "; $sql .= "VALUES({$data[1]}, {$data[2]},
> {$padded_number}) "; //mysql_query($sql) or die("Didn't
> insert you dumb ass.... FIX IT NOW CLOWN!!!! " .
> mysql_error());
> echo "SQL: " . $sql . "
";
>
> }
>
> }
> echo "File Bitches!";
> fclose($handle);
> }
>
>
>
> ?>
>
>
> Any ideas on what I'm missing?
>
> Thanks everyone!
>
> Jason Pruim
> lists@pruimphotography.com
SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, 200,
0001)
SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, 200,
0002)
Note the lack of single quotes on the third value; mysql will treat those as
integers - especially if subscriber is an integer type :-)
If you absolutely have to store the leading zeros you'll need to store them
in a char type and quote them when INSERTing or UPDATEing
Cheers
--
David Robley
<-------- The information went data way --------
Today is Boomtime, the 68th day of Bureaucracy in the YOLD 3177.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php