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

Jonathan Söder
Jonathan Söder
7,428 Points

[SOLVED] Need help with SQL and PHP not "accepting" certain values

  • SOLVED -

Hi! I'm on my way to finish my first big project (thanks to treehouse and its community!). Today I noticed a problem. I have a bot that fetches information and inserts information when I press a button. Everything works fine except the database does not "accept" any values from $imdb_score to $metacriticVotes.

$sql = mysqli_query($connect, 
    "INSERT INTO movies(
    Title, Year, Genre, Runtime, Director, Writer, Plot, Actors, Country, Language, IMDBscore, IMDB_votes, Rotten_tomato_score, Rotten_tomato_votes, 
    Metacritic_score, Metacritic_votes) 

    VALUES('$title', '$year', '$genre', '$runtime', '$director', '$writer', '$plot', '$actors', '$country', '$language', '$imdb_score', '$imdbVotes', '$rottenTomato', '$rottenTomatoVotes', 
        '$metacritic', '$metacriticVotes')"
    );

The fields I'm having problem with are of type VARCHAR (was uncertain of dots and commas when I created the database, the examples I looked at used varchar at the time). It doesn't help to change the columns to INT either. The values always results in BLANK in the database (ie nothing). Default is set to NULL.

//I fetch the values available in a form through these lines, (every line is the same, don't want to paste 16 more lines).
$title = mysqli_real_escape_string($connect, $_POST['title']);
$year = mysqli_real_escape_string($connect, $_POST['year']);
$genre = mysqli_real_escape_string($connect, $_POST['genre']);
...
//The bot fetches information (json) and I assign each value to a new variable.
$title = $array['Title'];
$year = $array['Year'];
$released = $array['Released'];
...

Also, entering information manually via SQL or edit directly in the database works. Anyone know what might be wrong? (also sorry for the naming conventions, I'm in the middle of changing it).

EDIT 1: The inserting values are in one of these two formats: "5.1" or "312,122"

Let me know if you need something more from me.

Thanks, Jon.

Brandon Berger
Brandon Berger
3,947 Points

A screenshot of your database table would be helpful.

Jonathan Söder
Jonathan Söder
7,428 Points

Hey man, I fixed it, I appreciate it though.