/    Sign up×
Community /Pin to ProfileBookmark

Are These Mysql Php Queries Valid Or Not ?

[code]
$sql_query = “SELECT id,username,first_name,surname FROM users WHERE $_SESSION[‘session_type’] = ?”;
[/code]

[code]
$sql_query = “SELECT id,username,first_name,surname FROM users WHERE $_GET[‘session_type’] = ?”;
[/code]

[code]
$sql_query = “SELECT id,username,first_name,surname FROM users WHERE $_POST[‘session_type’] = ?”;
[/code]

I forgot the other one, the third one out of the 3 ($_POST, $_GET, “”).
Imagine, I am asking about the 3rd one here too …

[code]
$sql_query = “SELECT id,username,first_name,surname FROM users WHERE $session_type = ?”;
[/code]

[code]
$sql_query = “SELECT id,username,first_name,surname FROM users WHERE ${$session_type} = ?”;
[/code]

to post a comment

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 25.2020 — The first term after the WHERE keyword should be a column name. I'm guessing that you do not want to use a session variable's value to determine what database column to check?
Copy linkTweet thisAlerts:
@developer_webauthorJan 29.2020 — @NogDog#1613655

Yes, the session variable value should match the column name.

This ain't working ...
<i>
</i> $sql_query = "SELECT id,username,first_name,surname FROM users WHERE $_SESSION['session_type'] = ?"; //This is line 354


Get error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:xampphtdocstestindex.php on line 354
Copy linkTweet thisAlerts:
@NogDogJan 29.2020 — Oh, either concatenate the array variable into the string, or use "complex" notation:
<i>
</i>// concatenation:
$sql_query = "SELECT id,username,first_name,surname FROM users WHERE ".$_SESSION['session_type']." = ?";

// complex notation:
$sql_query = "SELECT id,username,first_name,surname FROM users WHERE {$_SESSION['session_type']} = ?";
Copy linkTweet thisAlerts:
@ZharikovaIrinaJan 29.2020 — HI FOLKS!

We are looking for a best web designer!

Here are our awesome projects examples

[](https://hydraru4af.com/)


[](https://gidra-site.com/)


https://hydra-telegram.com/


https://hydra-kak-zaiti.com/


https://hydrach.com/

PAYMENT 100 Euro per hour.

Just send me your CV through email in my profile!

Cheers!!
×

Success!

Help @developer_web 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 3.29,
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: @darkwebsites540,
tipped: article
amount: 10 SATS,

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

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...