Note that there are some explanatory texts on larger screens.

plurals
  1. POclass users in my php code assistance?
    primarykey
    data
    text
    <p>I have the following code in my classes folder. When i execute it i get the following error </p> <blockquote> <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstname' cannot be null</p> </blockquote> <p>. i think the problem is in the first part of my code ? Is it the nameing of the variables?</p> <pre><code>&lt;?php class Users { public $username = null; public $firstname; public $lastname; public $firmname; public $email; public $password = null; public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w"; public function __construct( $data = array() ) { if( isset( $data['username'] ) ) $this-&gt;username = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['firstname'] ) ) $this-&gt;firstname = stripslashes( strip_tags( $data['lastname'] ) ); if( isset( $data['lastname'] ) ) $this-&gt;lastname = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['firmname'] ) ) $this-&gt;firmname = stripslashes( strip_tags( $data['firmname'] ) ); if( isset( $data['email'] ) ) $this-&gt;email = stripslashes( strip_tags( $data['email'] ) ); if( isset( $data['password'] ) ) $this-&gt;password = stripslashes( strip_tags( $data['password'] ) ); } public function storeFormValues( $params ) { //store the parameters $this-&gt;__construct( $params ); } public function userLogin() { $success = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1"; $stmt = $con-&gt;prepare( $sql ); $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR ); $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR ); $stmt-&gt;execute(); $valid = $stmt-&gt;fetchColumn(); if( $valid ) { $success = true; } $con = null; return $success; }catch (PDOException $e) { echo $e-&gt;getMessage(); return $success; } } public function register() { $correct = false; try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO users(username, firstname, lastname, firmname, email, password, date ) VALUES(:username, :firstname, :lastname, :firmname, :email, :password, NOW())"; $stmt = $con-&gt;prepare( $sql ); $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR ); $stmt-&gt;bindValue( "firstname", $this-&gt;firstname, PDO::PARAM_STR ); $stmt-&gt;bindValue( "lastname", $this-&gt;lastname, PDO::PARAM_STR ); $stmt-&gt;bindValue( "firmname", $this-&gt;firmname, PDO::PARAM_STR ); $stmt-&gt;bindValue( "email", $this-&gt;email, PDO::PARAM_STR ); $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR ); $stmt-&gt;execute(); return "Registration Successful &lt;br/&gt; &lt;a href='index.php'&gt;Login Now&lt;/a&gt;"; }catch( PDOException $e ) { return $e-&gt;getMessage(); } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload