/    Sign up×
Community /Pin to ProfileBookmark

Parse Error Inserting IP on the datae base

Why do I get this parse error message when I try to insert an ip into the data base.

[QUOTE]

Parse error: syntax error, unexpected T_DNUMBER

[/QUOTE]

Below is my code

[code=php]
$ip2=219.90.90.2;
$ip2=mysql_real_escape_string($ip2);

mysql_query(“INSERT INTO table_name(ip_string)
VALUES($ip2)”);[/code]

Now if I try to put single or double quote like this

[code=php] $ip2=’219.90.90.2′[/code]

the error will be gone, but it will not insert into the data base

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@anishgiriauthorApr 08.2013 — Ok I solve it I put a quote in my sql statement. Sometimes I am really forget full of these syntax/rules..
Copy linkTweet thisAlerts:
@NogDogApr 08.2013 — Ok I solve it I put a quote in my sql statement. Sometimes I am really forget full of these syntax/rules..[/QUOTE]

Moving up to either the MySQL[b]i[/b] extension or the PDO extension (instead of using the deprecated MySQL extension) can help you avoid that sort of problem by making use of prepared statements. It also automatically takes care of any escaping.

[code=php]
$sql = "INSERT INTO table_name(ip_string) VALUES(?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('s', $ip2); // handles all quoting/escaping issues for you
$stmt->execute();
[/code]
×

Success!

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