/    Sign up×
Community /Pin to ProfileBookmark

MySQLAdmin vs Browser

Why won’t this output any results when it’s within a method but when I add it into MySQL it works. I’ve returned the SQL, $t1 and $t2 values which are 33,465,44 for example.

I can’t insert code for some reason so it’s in the HTML tab here

https://jsfiddle.net/9b5pdh1x/

I get rows in mysqladmin and nothing when used in code in my browser. Both are using the same set of data

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmDec 29.2021 — Are you using the prepared statement in the admin test? Cause with PDO I"m pretty sure you cannot use a 'grouped' argument such as your imploded var which are probably not doing in the admin screen.
Copy linkTweet thisAlerts:
@NogDogDec 29.2021 — Yeah, the implode is going to create a string, and the prepared statement is going to put it into the IN() SQL expression as a single string (that happens to contain comma literals), rather than as multiple discrete values (integers?) separated by commas. If you are confident that $teamID could only contain integers, then it should be safe to just put the imploded $t1 directly into the $SQL assignment.
Copy linkTweet thisAlerts:
@ginerjmDec 29.2021 — In other words - just use a straight up query instead of a prepared one?
Copy linkTweet thisAlerts:
@NogDogDec 29.2021 — > @ginerjm#1641002 just use a straight up query instead of a prepared one?

Yeah, since those were the only two place-holders, doing a prepared statement is not necessary in this case. If there is any possibility those IDs could be corrupted, you could apply some sort of "sanitation" to them first, maybe just:
[code=php]
foreach($teamID as $ix => $id) {
$teamID[$ix] = (int) $id;
}
$t1 = implode(",", $teamID);
[/code]
Copy linkTweet thisAlerts:
@ginerjmDec 29.2021 — Regardless of the security of the input the reason to alter this query was because of the multiple values being supplied in a single parameter, no?
Copy linkTweet thisAlerts:
@NogDogDec 29.2021 — @ginerjm#1641004 Yep. The prepared query would have taken a string like "1, 2, 3" and put it into the actual query as WHERE teamID IN ('1, 2, 3'), which would then mean that MySQL would be looking for that entire string as a single value in that column, instead of looking for any of those three separate values. (Or MySQL might have returned an error about searching for a string in an integer field...not sure.)
Copy linkTweet thisAlerts:
@ginerjmDec 29.2021 — Exactly.
×

Success!

Help @kiwis 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 4.25,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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