2016-09-29 17:02
浏览 42


I'm trying to insert values in a table with a foreign key through php. The table is called games (id, title, year,genre, publisher_id). The other table does not contain foreign keys and it is as it follows: publisher(id,company, adress, prizes, published)...

Here's the code:

<h4>Insert new Game</h4>
    <form method="get">    

        <input type="text" name="new-game"                      
            <button type="submit">Submit Game</button>


  if (isset($_GET["new-game"])){

      $newgame= $_GET["new-game"];

      $id= mysqli_query($connection, "select max(id) from games");
      $maxid= mysqli_fetch_row($id)[0]+1;
      $publisher_id=mysqli_query($connection, "select title, company from publisher, games where");

      $insert ="insert into games (title, id, publisher_id) values (".$newgame.",".$maxid.",".$publisher_id.")";


      if (!$result) {
        echo "Erro na query ..." .mysqli_error($connection);


I get this error (points to the $insert line):Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\PHP\MG_Dinamico\admin.php on line 127

This is the config file:


    $user = 'root';
    $pwd = '';
    $server = 'localhost';
    $bdschema = 'MG';

    $connection = mysqli_connect($server,$user, $pwd, $bdschema);

if (mysqli_connect_error()) {
    echo "Error to DB ..." .mysqli_error($connection);

mysqli_set_charset($connection, "utf8");


I dont know how to put the query working...suggestions? Thanks in advance!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题