Home >> FAQs/Tutorials >> MySQL Tutorials

MySQL Tutorial - Fixing INSERT Command Denied Error

By: FYIcenter.com

(Continued from previous topic...)

How To Fix the INSERT Command Denied Error?

The reason for getting the "1142: INSERT command denied" error is that your user accound does not have the INSERT privilege on the table or database. To resolve this error, you need to ask your MySQL DBA to grant you the right privilege.

Your DBA will need to run commands like these to grant you enough privileges :

   GRANT INSERT ON fyi.* TO dev;
   GRANT UPDATE ON fyi.* TO dev;
   GRANT DELETE ON fyi.* TO dev;
   GRANT SELECT ON fyi.* TO dev;
   GRANT CREATE ON fyi.* TO dev;
   GRANT DROP ON fyi.* TO dev;

Once you got the right privileges, run the following tutorial scrip again:

<?php
  include "mysql_connection.php";

  $sql = "INSERT INTO fyi_links (id, url) VALUES ("
      . " 101, 'dev.fyicenter.com')";
  if (mysql_query($sql, $con)) {
    print(mysql_affected_rows() . " rows inserted.\n");
  } else {
    print("SQL statement failed with error:\n");
    print(mysql_errno($con).": ".mysql_error($con)."\n");
  }

  $sql = "INSERT INTO fyi_links (id, url) VALUES ("
      . " 102, 'dba.fyicenter.com')";
  if (mysql_query($sql, $con)) {
    print(mysql_affected_rows() . " rows inserted.\n");
  } else {
    print("SQL statement failed with error:\n");
    print(mysql_errno($con).": ".mysql_error($con)."\n");
  }

  mysql_close($con); 
?>

The script should return this:

1 rows inserted.
1 rows inserted.

(Continued on next topic...)

  1. How To Create a New Table?
  2. How To Get the Number of Rows Selected or Affected by a SQL Statement?
  3. How To Insert Data into an Existing Table?
  4. How To Fix the INSERT Command Denied Error?
  5. How To Insert Multiple Rows with a SELECT Statement?
  6. What Is a Result Set Object?
  7. How To Query Tables and Loop through the Returning Rows?
  8. How To Break Query Output into Pages?
  9. How To Update Existing Rows in a Table?
  10. How To Delete Existing Rows in a Table?
  11. How To Quote Text Values in SQL Statements?
  12. How To Quote Date and Time Values in SQL Statements?
  13. How To Display a Past Time in Days, Hours and Minutes?
  14. How To Perform Key Word Search in Tables?
  15. How To Build WHERE Criteria with Web Form Search Fields?
  16. How To Query Multiple Tables Jointly?
  17. How To Define the ID Column as Auto-Incremented?
  18. How To Get the Last ID Assigned by MySQL?

MySQL Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...