php - I can connect to mysql db but my table is not updating -
i able connect mysql db have created table called attorney_users. know missing or doing wrong? have post function code below. when register user confirms success, table not updated.
<?php require_once('appvars.php'); require_once('connectvars.php'); // connect database $dbc = mysqli_connect(db_host, db_user, db_password, db_name); if (isset($_post['submit'])) { // grab profile data post $username = mysqli_real_escape_string($dbc, trim($_post['username'])); $firstname = mysqli_real_escape_string($dbc, trim($_post['firstname'])); $lastname = mysqli_real_escape_string($dbc, trim($_post['lastname'])); $firmname = mysqli_real_escape_string($dbc, trim($_post['firmname'])); $email = mysqli_real_escape_string($dbc, trim($_post['email'])); $password = mysqli_real_escape_string($dbc, trim($_post['password'])); $password2 = mysqli_real_escape_string($dbc, trim($_post['password2'])); if (!empty($username) && !empty($password) && !empty($password2) && ($password == $password2)) { // make sure isn't registered using username $query = "select * attorney_users username = '$username'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // username unique, insert data database $query = "insert attorney_users (username, firstname, lastname, firmname, email, password, date) values ('$username', '$firstname', '$lastname', $firmname, $email, sha('$password'), now())"; mysqli_query($dbc, $query); // confirm success user echo '<p>your new account has been created. you\'re ready <a href="index.php">log in</a>.</p>'; mysqli_close($dbc); exit(); } else { // account exists username, display error message echo '<p class="error">an account exists username. please use different username.</p>'; $username = ""; } } else { echo '<p class="error">you must enter of sign-up data, including desired password twice.</p>'; } } mysqli_close($dbc); ?> <div id="main-wrapper"> <div id="register-wrapper"> <form method="post" action = "<?php echo $_server['php_self'];?>"> <fieldset> <ul> <label for="username">username : </label> <input type="text" id="username" name = "username" value = "<?php if (!empty($username)) echo $username; ?>" /> <label for="firstname">first name : </label> <input type="text" id="firstname" name = "firstname" /> <label for="lastname">last name : </label> <input type="text" id="lastname" name = "lastname" /> <label for="firmn">firm name : </label> <input type="text" id="firmname" name = "firmname" /> <label for="email">email : </label> <input type="text" id="email" name = "email" /> <label for="password">password : </label> <input type="password" id="password" name="password" /> <label for="password2">verify password : </label> <input type="password" id="password2" name="password2" /> </li> <li class="buttons"> <input type="submit" value="register" name="submit" /> <input type="button" name="cancel" value="cancel" onclick="location.href='index.php'" /> </li> </ul> </fieldset> </form> </div> </div> </body> </html>
date
reserved in mysql
, use ` around column name
$query = "insert attorney_users (`username`, `firstname`, `lastname`, `firmname`, `email`, `password`, `date`) values ('$username', '$firstname', '$lastname', $firmname, $email, sha('$password'), now())";
and why using mysqli_real_escape_string
escaping , can use prepared statement here.
edit
use checking error in query
$data = mysqli_query($dbc, $query) or die(mysqli_error());