Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
NDD Camp 2024

Can't figure out what's wrong with it MySQL and PHP

Status
Not open for further replies.

EM @MAJ.com

Visit MAJ.com for domain forsale.
Legacy Exclusive Member
Joined
Sep 10, 2002
Messages
5,833
Reaction score
75
I have the following mysql table structures.
field1 - int
field2 - int
field3 - varchar(100)

To insert data through MySQL:
INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES
(0-1234567, 1350841806, 0xC02E1B43BA78800200),

I run a query.
SELECT * FROM `table`
the field1 out is -1234567, omitting the prefix 0
the field3 output show a 'unreadable data' but that's fine because I can use Hex(field3) to show me the hex value.

To insert data through PHP script:
When I create a php insert.php with the following code?
$sql="INSERT INTO table (field1, field2, field3) VALUES ('$field1','$field2','$field3')";

I run a query.
SELECT * FROM `table`
the field1 output is 0-1234567, this the actual data retaining the beginning 0 (zero).
the field3 output is 0xC02E1B43BA78800200, not the 'unreadable data'

Why the field1 and field3 is not the same value when I insert through MySQL (phpAdmin) and using PHP script?

Thank you,
em @ king.net
 

NamePrime

nameprime.com
Legacy Platinum Member
Joined
Feb 15, 2010
Messages
839
Reaction score
18
if you're inserting this exact value '0-1234567', your field type should not be an int. Try to change in to varchar. field3 value should be enclosed by single-quote '0xC02E1B43BA78800200' to be interpreted as string

table should be:
field1 - varchar(length-here)
field2 - int
field3 - varchar(100)

insert query

INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES
('0-1234567', 1350841806, '0xC02E1B43BA78800200')
 

EM @MAJ.com

Visit MAJ.com for domain forsale.
Legacy Exclusive Member
Joined
Sep 10, 2002
Messages
5,833
Reaction score
75
I will try it kababayan.

Salamat.
em @ king.net
 

Gerry

Dances With Dogs
Legacy Exclusive Member
Joined
Dec 3, 2006
Messages
14,985
Reaction score
1,302
Give me 12 more weeks and I may be able to help as I am taking a MySQL and PHP class right now.
 

EM @MAJ.com

Visit MAJ.com for domain forsale.
Legacy Exclusive Member
Joined
Sep 10, 2002
Messages
5,833
Reaction score
75
Thanks Gerry. I will depend you on :)
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
MariaBuy

Our Mods' Businesses

URL Shortener
UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom