/    Sign up×
Community /Pin to ProfileBookmark

Incorrect integer value: ” for column

I have a problem with a line of sql and php code. I keep getting this error and I’m so confused as to what it is

the problem:
`Incorrect integer value: ” for column ‘ID’ at row 1`

the sql code:
`CREATE TABLE `attendanceout` (
`
out_ID` int(10) NOT NULL,
`
ID` int(10) NOT NULL,
`
time_out` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`
date_info` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`
Room` varchar(100) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;`

then:
`
ALTER TABLE `
attendanceout`
ADD PRIMARY KEY (`
out_ID`);
ALTER TABLE `
attendanceout`
MODIFY `
out_ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
`

this is the php script:
`$sql = “INSERT INTO attendanceout (out_ID, ID, time_out, date_info, Room)
VALUES (‘$out_id’, ‘$id’, ‘$time’, ‘$date’, ‘$dataSendOut’)”;`

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 03.2020 — Remove the quotes around $out_id and $id in the query, since they are numeric fields, not strings.

Also, if you are not going to use prepared statements with bound values, I hope you are sanitizing those values before using them in the query?
Copy linkTweet thisAlerts:
@frncsknauthorJul 03.2020 — @NogDog#1620217

I tried removing the quotes before I posted the question and I get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '

can you elaborate on the your second statement? because it seems that I haven't sanitized the values
Copy linkTweet thisAlerts:
@NogDogJul 03.2020 — > @frncskn#1620212 Incorrect integer value: '' for column 'ID' at row 1

Actually, that's making me wonder if $id is empty?

As far as sanitizing goes, you do not want to use any values from external sources (form fields, cookie/session values, etc.) directly in a query, in case they contain values that will break things in the SQL (either accidentally or maliciously). Specifics on how to do that will depend on which PHP database extension you are using, and whether the use of prepared statements is an option in that extension or if you need to explicitly sanitize each value.

Search on "SQL injection" for more info on why.

A very brief explanation: [XKCD SQL injection cartoon](https://imgs.xkcd.com/comics/exploits_of_a_mom.png). :)
Copy linkTweet thisAlerts:
@frncsknauthorJul 07.2020 — @NogDog#1620220 yes both $out_id and $id are empty. they are dependent on the user
Copy linkTweet thisAlerts:
@NogDogJul 07.2020 — Then you probably should verify that they are populated before you try to use them. ;)
Copy linkTweet thisAlerts:
@frncsknauthorJul 07.2020 — @NogDog#1620293 this will be done in the php right?

EDIT:

This is the full error I'm getting right now:

`2: INSERT INTO attendancetracking (out_ID, id, time_in, Date_info, room, status) VALUES ('', '', '10:32:AM', '7-7-2020', '', '1')<br/>
Incorrect integer value: '' for column 'out_ID' at row 1
</C>

another edit:

I experimented and replaced <C>
$ATT_ID and $id</C> with an integer like 2, 2 the error disappeared but I would like to retain the <C>$ATT_ID and $id`
because those values will be filled with the id when an user account is created or when he/she logs in
Copy linkTweet thisAlerts:
@NogDogJul 07.2020 — > @frncskn#1620294 those values will be filled with the id when an user account is created or when he/she logs in

So, in the PHP it appears you then need to confirm that both of them exist with non-empty values before you try to do anything with them in the database query. Since I don't know where they come from, I cannot give specific suggestions. Find where they get set, figure out how/why they could end up either not being set or being set to an empty string. Then if it's due to a bug in your code, fix it; but if it's due to possible user error, add logic to handle it without actually trying to do the query (display an error message, maybe?). At it's simplest:
<i>
</i>if(trim($some_var) === '' or trim($another_var) === '') {
// display an error message here about missing required things
}
else {
// go ahead and do stuff with those variables
}

Not the only way, or even the best way, but a fairly straight-forward way, at least.
Copy linkTweet thisAlerts:
@frncsknauthorJul 07.2020 — @NogDog#1620301 thanks a lot! Will look into it
×

Success!

Help @frncskn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...