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
Post a Comment