Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:56:03+00:00 2026-06-04T14:56:03+00:00

Getting a MySQL error message when I try to insert a text message from

  • 0

Getting a MySQL error message when I try to insert a text message from a form element into my database setup to receive as type VARCHAR with a max 999 characters. I also tried setting type as TEXT. Perhaps there is something I’m just not seeing here. Error states its a syntax error, but I don’t see one. I’m using MySQL ver 5.1

Error message reads:

“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘key (number, category, question, answertxt, answer, correct, incorrect, feedback’ at line 1”.

Here is my submitting form (create.php):

    <?php

    session_start(); //start sesson.

    $error = false;
    $error = $_SESSION['error'];

    if($error){
        echo '<div class="error">Please fill in all required fields indicated by the * symbol</div>';
    }

    ?>

    <form action="db_adddata.php" method="post">

    <label>Category</label><br>
    <input type="text" id="category" name="category" value="" maxlength="50">*<br>

    <label>Question text</label><br>
    <textarea id="question" name="question" rows="7" cols="20"></textarea>*<br>

    <label>Answer text</label><br>
    <textarea id="answertxt" name="answertxt" rows="7" cols="20"></textarea>*<br>

    <label>Accepted  answers (comma separated)</label><br>
    <textarea id="answer" name="answer" rows="7" cols="20"></textarea>*<br>

    <label>Correct answer response</label><br>
    <textarea id="correct" name="correct" rows="7" cols="20"></textarea>*<br>

    <label>Incorrect answer response</label><br>
    <textarea id="incorrect" name="incorrect" rows="7" cols="20"></textarea>*<br>

    <label>Feedback response</label><br>
    <textarea id="feedback" name="feedback" rows="7" cols="20"></textarea>*<br>

    <label>Lesson refferal response</label><br>
    <textarea id="lessonref" name="lessonref" rows="7" cols="20"></textarea>*<br>

    <input type="submit" value="submit">

    </form>

And here is the processing script (db_adddata.php):

    <?php

session_start(); //start sesson.
require('db_connect.php'); //connect to the database.

//assign variables with the data we posted from the form on the previous page.

$category = $_POST['category'];
$question = $_POST['question'];
$answertxt = $_POST['answertxt'];
$answer = $_POST['answer'];
$correct = $_POST['correct'];
$incorrect = $_POST['incorrect'];
$feedback = $_POST['feedback'];
$lessonref = $_POST['lessonref'];

//assign vars to session vars.

$_SESSION['category'] = $category;
$_SESSION['question'] = $question;
$_SESSION['answertxt'] = $answertxt;
$_SESSION['answer'] = $answer;
$_SESSION['correct'] = $correct;
$_SESSION['incorrect'] = $incorrect;
$_SESSION['feedback'] = $feedback;
$_SESSION['lessonref'] = $lessonref;


//check if vars are empty if yes deny and go to error page. Otherwise continue.

if(empty($category) || empty($question) || empty($answertxt) || empty($answer) || empty($correct) || empty($incorrect) || empty($feedback) || empty($lessonref)) {

    $_SESSION['error'] = true; //set error as true.
    header('Location: create.php'); //go back to form page.

}
else {

    //add the data to the database.

    mysql_query("INSERT INTO key (number, category, question, answertxt, answer, correct, incorrect, feedback, lessonref, datemod) VALUES ('','$category','$question','$answertxt','$answer','$correct','$incorrect','$feedback','$lessonref',CURDATE())")or die(mysql_error());

    header('Location: viewkey.php'); // go to view key page.
}

mysql_close(); //close connection.

    ?>

Below is a info of my MySQL table info for table named ‘key’:

Field | Type | Collation | EXTRA


number | int(6) | | AUTO_INCREMENT (primary)


category | varchar(999) | latin1_general_ci |


question | varchar(999) | latin1_general_ci |


answertxt | varchar(999) | latin1_general_ci |


answer | varchar(999) | latin1_general_ci |


correct | varchar(999) | latin1_general_ci |


incorrect | varchar(999) | latin1_general_ci |


feedback | varchar(999) | latin1_general_ci |


lessonref | varchar(999) | latin1_general_ci |


datemod | date | |


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:56:05+00:00Added an answer on June 4, 2026 at 2:56 pm

    key is a reserved word in mySQL. You need to surround that table with backticks:

    INSERT HIGH_PRIORITY INTO `key` ... etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On form submit, I'm getting a blank page (insert.php) with no error and no
I am getting the error: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server
Getting a 'marshal data too short' error when trying to install the mysql gem
I am trying to connect to mysql and am getting an error. I put
If I'm getting my data from Mysql like so: $result = $dbConnector->Query(SELECT * FROM
I am having trouble getting well formatted results from my mysql query. Here is
I keep getting MySQL error #1054, when trying to perform this update query: UPDATE
I am getting this error message: --------------------------- You have an error in your SQL
I am getting the following error message while installing, let me know if I
I keep getting the following error message when trying to UPDATE one of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.