Error when inserting into table

I get this: Catchable fatal error: Object of class mysqli could not be converted to string error when i want to insert data into my games table. On my games.php i have a form that sends data to games_add.php and error occurs on line 18 in games_add.php.

(i know a lot of code) game.php code:

<body>
  <form action="games_add.php" method="post">
Game name: <input type="text" name="game_name" placeholder="Enter first name ..." required="required" /><br />
Relese date: <input type="date" name="relese_date" placeholder="Enter  relese date ..." required="required" /><br />
Introduction: <input type="text" name="introduction" placeholder="Enter introduction ..."  required="required" /><br />
Description: <input type="text" name="description" placeholder="Enter description ..."  required="required" /><br />
Original price: <input type="number" name="rating" placeholder="Enter original price ..." required="required" /><br />

Developer: <select name="developer_id">
    <?php 
    include_once 'connection.php';
        $query = "SELECT * FROM developers";
        $result = mysqli_query($link, $query);
        while ($row = mysqli_fetch_array($result)) {
             echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
        }     
    ?>
</select>    

    Publisher: <select name="publisher_id">
    <?php 
    include_once 'connection.php';
        $query = "SELECT * FROM publishers";
        $result = mysqli_query($link, $query);
        while ($row = mysqli_fetch_array($result)) {
             echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
        }     
    ?>
</select> 



    Categories: <select name="categories_id">
    <?php 
    include_once 'connection.php';
        $query = "SELECT * FROM categories";
        $result = mysqli_query($link, $query);
        while ($row = mysqli_fetch_array($result)) {
             echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
        }     
    ?>
</select>



    Platform: <select name="platform1_id">
    <?php 
    include_once 'connection.php';
        $query = "SELECT * FROM platforms";
        $result = mysqli_query($link, $query);
        while ($row = mysqli_fetch_array($result)) {
             echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
        }     
    ?>
</select>


<input type="submit" value="Insert" />
<input type="reset" value="Cancle" />

games_add.php code:

      <?php
    include_once 'connection.php';

        $game_name = $_POST['game_name'];
        $relese_date = $_POST['relese_date'];
        $introduction = $_POST['introduction'];
        $description = $_POST['description'];
        $rating = $_POST['rating'];
        $developer_id = $_POST['developer_id'];
        $publisher_id = $_POST['publisher_id'];
        $categories_id = $_POST['categories_id'];
        $platform1_id = $_POST['platform1_id'];
        $avrage_score = 33;



            $query = sprintf("INSERT INTO games (game_name, relese_date, introduction, description, rating, developer_id, publisher_id, categories_id, platform1_id, avrage_score ) 
                              VALUES ('%s','$relese_date','%s','%s','$rating','%s','%s','%s','%s','$avrage_score') or die(mysqli_error($link)); ",
                             mysqli_real_escape_string($link, $game_name),
                             mysqli_real_escape_string($link, $introduction),
                             mysqli_real_escape_string($link, $description),
                             mysqli_real_escape_string($link, $developer_id),
                             mysqli_real_escape_string($link, $publisher_id),
                             mysqli_real_escape_string($link, $categories_id),
                             mysqli_real_escape_string($link, $platform1_id));                
            mysqli_query($link, $query);
 header('Location: games.php');
?>

Picture of my database if it helps. enter image description here

1 answer

  • answered 2017-06-17 18:12 Rickard

    Are you sure you want "or die(mysqli_error($link))" to be part of your SQL and not part of your PHP?