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>
</form>
<?php
if (isset($_GET["new-game"])){
require("MGconfig.php");
$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 publisher.id=publisher_id");
$insert ="insert into games (title, id, publisher_id) values (".$newgame.",".$maxid.",".$publisher_id.")";
$result=mysqli_query($connection,$insert);
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:
<?php
$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);
exit;
};
mysqli_set_charset($connection, "utf8");
//print_r($connection);
?>
I dont know how to put the query working...suggestions? Thanks in advance!