0

I am working on a site to make DnD character sheets for my friends and I. The first part is done and data is POST-ing correctly but will not upload to server. I have worked on this problem for along time and still cannot figure it out. All of the stuff is spelled the same as server and the server is connected. The error I get with mysqli_error() is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server for the right syntax to use near'character(id, username, characterName, class, level, race, alignment, deity, si' at line 1

I put echo before the problem to make sure everything is working before uploaded and everything is working fine but will not upload. The $bd is connection and is working because i use it with other pages.

This is my code:

echo ($id . "<br />");
echo ($username . "<br />");
echo ($characterName . "<br />");
echo ($class . "<br />");
echo ($level . "<br />");
echo ($race . "<br />");
echo ($alignment . "<br />");
echo ($deity . "<br />");
echo ($size . "<br />");
echo ($age . "<br />");
echo ($gender . "<br />");
echo ($height . "<br />");
echo ($weight . "<br />");
echo ($eyes . "<br />");
echo ($hair . "<br />");
echo ($skin . "<br />");
echo ($mysql_hostname . "<br />");
echo ($mysql_user . "<br />");
echo ($mysql_password . "<br />");
echo ($mysql_database . "<br />");

if(isset($_POST['nc1']))

{
$query    =    "INSERT INTO characters (id, username, characterName, class, level, race,  alignment, deity, size, age, gender, height, weight, eyes, hair, skin) VALUES ('$id', '$username', '$characterName', '$class', '$level', '$race', '$alignment', '$deity', '$size',     '$age', '$gender', '$height', '$weight', '$eyes', '$hair', '$skin')";
mysqli_query($bd,$query) or die('Error: ' . mysqli_error($bd));
//header('location:success.php');//Redirect To Success Page
echo ("success");
}
2
  • 1
    can you post the content of $query? Commented Jan 29, 2014 at 19:11
  • Thank you all so much, i changed the table name and it works perfectly. I did not understand what the error meant so thank you. Commented Jan 31, 2014 at 1:58

2 Answers 2

3

character is a reserved word in mysql. If you use this as a tablename, you must quote that:

$query = "INSERT INTO `character` ( `id`, `username`, ....

As a good practice and in order to prevent such faults, always quote table or column names.

Sign up to request clarification or add additional context in comments.

Comments

0

It is said in here that your table name character is a reserved word, so you need to changed that, else your code wont work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.