/    Sign up×
Community /Pin to ProfileBookmark

Hi there,
I can’t find where I made a mistake, for years…
$row = “INSERT INTO Student (Name, Surename, StudentID, Generation) VALUES (‘$_POST[$student_data[0]]’, ‘$_POST[$student_data[1]]’, ‘$_POST[$student_data

[2]]’, ‘$_POST[$student_data[3]]’)”;

This is report: Parse error: syntax error, unexpected ‘[‘, expecting ‘]’ in
Thanks in advance…

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@epricityMay 15.2013 — With the disclaimer that this is the worst possible coding practice, because you're wide open to SQL injection attacks if you write your code this way, here's the solution. You need to escape your strings. Like this.

$row = "INSERT INTO Student (Name, Surename, StudentID, Generation) VALUES ('{$_POST[$student_data[0]]}', '{$_POST[$student_data[1]]}', '{$_POST[$student_data[2]]}', '{$_POST[$student_data[3]]}')";
×

Success!

Help @noahwilson 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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