mysql - PHP PDO error 1064 -


i'm having small issues, when submit data on forum error:

sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'explain, country, ip, hostname) 

my code this:

        $sth = $dbh->prepare("insert `applications` (`username`, `email`, `age`, `reason`, `explain`, `country`, `ip`, `hostname`) values ($username, $email, $age, $reason, $explain, $country, $ip, $hostname)");         $sth->execute();

i can't seem find problem.

you're not using pdo correctly, creating massive sql injection problems. values put sql need escaped properly.

the placeholder method dictates doing way:

$sth = $dbh->prepare("insert `applications` (`username`, `email`, `age`, `reason`, `explain`, `country`, `ip`, `hostname`) values (:username, :email, :age, :reason, :explain, :country, :ip, :hostname)"); $sth->bindparam(':username', $username); $sth->bindparam(':email', $email); ... (remaining columns) .. $sth->bindparam(':hostname', $hostname); $sth->execute(); 

this best way ensure sql properly escaped.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -