skip to Main Content

I have numerous error checkers which the newly inputted code successfully meet the requirements of, however, the data doesnt seem to be going into the database. Its not updating, therefore i believe theres something wrong with my line of update code

"UPDATE user (user_username, user_first, user_last, user_email) VALUES ('$uname', '$first', '$last', '$email');";

Basically want the new information typed in my input boxes to be inserted into the database

3

Answers


  1. You’re not using the MySQL syntax for inserting a new row:

    INSERT INTO tblName (col1, col2, col3) VALUES (x, y, z);

    You have the UPDATE keyword instead.

    Login or Signup to reply.
  2. For inserting data you query will be

    INSERT INTO user (user_username, user_first, user_last, user_email) 
    VALUES ('$uname', '$first', '$last', '$email')
    

    But if you want to UPDATE your data, you need use the UPDATE clause correctly.

    Login or Signup to reply.
  3. Building on @Tim’s answer, you should probably also use a prepared statement. The prepared statement will protect you from mysql injection, which could possibly destroy your database.

    http://php.net/manual/en/pdo.prepared-statements.php

    <?php
    $stmt = $dbh->prepare("INSERT INTO user (user_username, user_first, user_last, user_email) VALUES (:usr, :first, :last, :email)");
    $stmt->bindParam(':usr', $uname);
    $stmt->bindParam(':first', $first);
    $stmt->bindParam(':last', $last);
    $stmt->bindParam(':email', $email);
    
    $stmt->execute();
    
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search