Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.