php - Unable to insert data into database using PDO -


I have written this code for a registration page, but I used to insert data into my database using PDO (or PDO) I am unable to do something wrong; Here is the registration page code:

   gt; & Lt; Br / & gt; & Lt; "Password" for label & gt; Password: & lt; / Label & gt; & Lt; Input type = "password" name = "password" /> & Lt; Br / & gt; & Lt; For the label "fname" & gt; First name: & lt; / Label & gt; & Lt; Input type = "text" name = "fname" /> & Lt; Br / & gt; & Lt; "Lname" for label & gt; Last name: & lt; / Label & gt; & Lt; Input type = "text" name = "lname" /> gt; & Lt; Br / & gt; & Lt; "Email" & gt; for label Email: & lt; / Label & gt; & Lt; Input type = "text" name = "email" /> gt; & Lt; Br / & gt; & Lt; Button type = "submit" & gt; Submit & lt; / Button & gt; & Lt; / Form & gt; & Lt ;? Php} and {$ form = $ _POST; $ Username = $ form ['username']; $ Password = $ form ['passwd']; $ Fname = $ form ['fname']; $ Lname = $ form ['lname']; $ Email = $ form ['email']; $ User = 'root'; $ Pass = 'pdt1848!'; $ Db = new PDO ('mysql: host = localhost; dbname = phpproject', $ user, $ pass); $ sql = "Include user (username, password, FNN, LNA, email) values ​​(: username, password :: fname,: lname, email:)"; $ Query = $ db- & gt; Ready ($ sql); $ Result = $ query- & gt; Execution (array (': username' = & gt; $ username, ': password' = & gt; $ password, ': fname' = & gt; $ fname, ': lname' = & gt; $ Lname, : Email '= & gt; $ email)); If ($ result) {echo "Thanks for registering with us!"; } Else {echo "Sorry, there was an error while editing the database, contact the person who created this garbage."; }; }; ? & Gt;    

The error is correct, passowrd < Previous> $ password = $ form ['passowrd'];

The only typo

Change it to:

  $ password = $ form ['password'];   

When anyone fails, the entire query fails.

If you reported error in your code, then it will be picked up immediately.

The way you can use in the future, try a try and amp; Hold method, like:

  Try {$ dbh = new PDO ($ DSN, $ user, $ password); $ Dbh- & gt; Set Attribution (PDO :: ATTRRAMOD, PDO :: ERRMODxEpeps); } Hold (PDOException $ e) {echo 'connection failed:'. $ E & gt; getMessage (); }   

Also

  error_reporting (E_ALL); Ini_set ('display_errors', 1);   

The link that you can consult to read:

PDO

  • /

  • Password

    I also noticed that you The passwords are stored in plain text. It is not recommended.

    Use one of the following:

    • Compatibility pack (if PHP & lt; 5.5)
    • Other links :



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -