/    Sign up×
Community /Pin to ProfileBookmark

Insert record in mySQL (should be easy)

Hi,

I am new with PHP. I try to insert a record into the table. The insert syntax is working when I specified the value manually like this:

[CODE]mysql_query(“INSERT INTO scriptactlog (login, scriptname, scriptoutput) VALUES (‘testing1’, ‘testing2’, ‘testing3’)”);[/CODE]

But when I try to use variable as values like this, it didn’t work. What is the mySQL syntax for using variable?

[CODE]mysql_query(“INSERT INTO scriptactlog (login, scriptname, scriptoutput) VALUES ($LoginName, $ScriptName, $scriptoutput)”);[/CODE]

Thank you,

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SunnyVuauthorMar 06.2007 — Found it,

Just need single quote before/end variable.

[CODE]mysql_query("INSERT INTO scriptactlog (login, scriptname, scriptoutput) VALUES ('$LoginName', '$ScriptName', '$scriptoutput')");[/CODE]
Copy linkTweet thisAlerts:
@MrCoderMar 06.2007 — Dont forget to use mysql_real_escape_string()
×

Success!

Help @SunnyVu 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.18,
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,
)...