Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Torger Angeltveit
Torger Angeltveit
11,228 Points

MYSQL / PHP uploading error

Hi, so i have some trouble with uploading some data to a mysql database through a html form, the code looks like this:

   if(isset($_POST['submit'])){
    $achievement = $_POST["achievement-name"];
    $category = $_POST["category"];
    //validation for the form
        if($achievement == "")
        {
            echo "You must fill out all the fields";
        } 
            else 
        {
            $sqlAchiv = "INSERT INTO user(achievement-name, category)VALUES ('$achievement', '$category')";

                if(mysqli_query($con, $sqlAchiv)) 
                {
                    echo "Achievement Unlocked!";
                } 
                    else 
                {
                    echo "Failed to unlock achievement";
                }
            }   
        }

The error: Failed to unlock achievement appears when i submit the form. I've trippled checked the variables and post names so it shouldnt be anything wrong with them.

1 Answer

Torger Angeltveit
Torger Angeltveit
11,228 Points

I got it to work! :) The problem was i couldnt store data in the database when the name of the column contained " - " in it.