简体   繁体   中英

Sql not accepting values in php

php

 $dnumber = '9515551212';
 $device_id = 'f3847010927038970110923';  

device is a text field phnum (I have used bigint, text, varchar) all give the same result.

 mysql_query("INSERT INTO devices(device, phnum) VALUES('$device_id', '$dnumber')");

the above query is TRUE but the value in phnum will be empty.

 mysql_query("INSERT INTO devices(device, phnum) VALUES('$device_id', $dnumber)");

the above query is FALSE, but it still inserts the record perfectly! I also get error 1064 near ")" (I removed the quotes from $dnumber)

So why is the first saying it succeeded but didnt put anything there while second says it fails but it inserted it as I wanted it to?

I think, there's something with incoming data. SQL works well.

I tried that query from php:

$sql = "INSERT INTO test(device_id, phnum) VALUES('$device_id', '$dnumber')";
$res = mysql_query($sql);

For the table with the following structure:

CREATE TABLE `test` (
  `phnum` int(30) unsigned NOT NULL AUTO_INCREMENT,
  `device_id` varchar(256) NOT NULL DEFAULT '',
  PRIMARY KEY (`phnum`)
) ENGINE=InnoDB AUTO_INCREMENT=4294967295 DEFAULT CHARSET=utf8;

It worked well without any warnings. From SQL client - the same, works well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM