0

My question is, how do I insert the current ID of my Game ID into the database. Here is my table: game_review mySQL

I want to insert the current user_id and title and description, which i already know how to do. (I'm not worrying about errors checking or security yet.) I just cannot insert the current ID of the game that I clicked on.

Here is my code:

<?php

    require_once $_SERVER['DOCUMENT_ROOT'].'/Gamesite/core/init.php';
    include('head.php');
    include('navigation.php');

?>

    <div class="container" style="padding-top: 200px;">

<?php

    // Get the current ID of the game
    $game_id = $_GET['id'];

    $errors = array();

    // Get the user ID from init.php
    $user_id = $user_data['id'];

    if (isset($_POST['submit'])) {


        // Sanitize form fields.
        $title = ((isset($_POST['title']) && $_POST['title'] != '') ? sanitize($_POST['title']) : '');
        $review = ((isset($_POST['review']) && $_POST['review'] != '') ? sanitize($_POST['review']) : '');
        $rating = ((isset($_POST['rating']) && $_POST['rating'] != '') ? sanitize($_POST['rating']) : '');


        if (!empty($errors)) {
            display_errors($errors);
        } else {

            $SQL_INSERT = "insert into game_review (`user_id`, `game_id`, `rating`, `title`, `review`) VALUES ('$user_id', '$game_id', '$rating', '$title', '$review')";
            $QUERY = $db->query($SQL_INSERT);
            //header('Location: Review.php');
        }

    }


?>

When I click submit in the form, this error message show up.

Notice: Undefined index: id in C:\xampp\htdocs\Gamesite\game_includes\Review.php on line 14

It says this question is a duplicate, can you please redirect me to a similar answer to my question?

Im sorry, I looked at that question that you redirected me, but thats not the question I was asking for.

David
  • 1,987
  • 5
  • 33
  • 65
  • `$_GET['id']` not defined so you cant insert it in to the db. –  Nov 08 '15 at 04:27
  • Do you have any clue of how I would define the current ID of the game? Because when I click on Review.php, the URL is Review.php?id=7(Or what ever game i clicked on) But when I submit my review comment, it just goes back to Review.php without the id # in the URL, Is that why it is undefined? – David Nov 08 '15 at 05:02
  • If you want the id in the url after a form submit. The action url must have that id in it –  Nov 08 '15 at 06:32
  • Oh my god, ur right, I had to echo the current game id in the action. Like this.
    Thank You!
    – David Nov 08 '15 at 08:43

0 Answers0