php - Registration form SQL syntax error -


i'm trying make simple registration form. when error says have error in sql syntax.

but says have problem on line wrote:

$stmt->execute(); 

i guess it's because can not execute sql question?

my code:

<?php require 'anslut.php';  $submit = filter_input(input_post, "submit", filter_sanitize_special_chars);  $output = ""; if (isset($submit)) {     $name = filter_input(input_post, "name", filter_sanitize_special_chars);     $username = filter_input(input_post, "username", filter_sanitize_special_chars);     $password = filter_input(input_post, "password", filter_sanitize_special_chars);   if ($name == "" || $username == "" || $password == "") {     $output .= "all fields must entered"; } else {     $sql = "insert users(username, password, namn) values :username, :password, :name";     $stmt = $dbh->prepare($sql);     $stmt->bindparam(":username", $username, pdo::param_str);     $stmt->bindparam(":password", $password, pdo::param_str);     $stmt->bindparam(":name", $name, pdo::param_str);     $stmt->execute();      $output .= "registration successful";     $output .= "<a href='index.php'>follow link log in</a>";     } } ?> <html>     <head>         <title>register here</title>         <meta charset="utf-8">     </head>     <body>         <form method="post">             <table>                 <tr>                     <td><label>your name:</label></td>                     <td><input type="text" name="name" placeholder="your name"></td>                 </tr>                 <tr>                     <td><label>username:</label></td>                     <td><input type="text" name="username" placeholder="username"></td>                 </tr>                 <tr>                     <td><label>password:</label></td>                     <td><input type="password" name="password" placeholder="password"></td>                 </tr>                 <tr>                     <td></td>                     <td><button type="submit" name="submit">register</button></td>                 </tr>             </table>         </form>         <?php print($output); ?>     </body>  </html> 

looking @ sql query:

insert users(username, password, namn) values :username, :password, :name                           spelling? -----^         ^------ parentheses ------^ 

the spelling 1 guess, @ least parentheses idea. maybe meant this?:

insert users(username, password, name) values (:username, :password, :name) 

also, side note, never store user passwords in plain text. irresponsible handling of user data. php has lot of built-in functionality assist in obscuring user passwords behind one-way hash. (as a compatibility pack older php versions.)


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -