我明白了:可捕获的致命错误:当我想将数据插入到我的游戏桌中时,类mysqli的对象无法转换为字符串错误。 在我的games.php上,我有一个将数据发送到games_add.php的表单,并且在games_add.php的第18行发生错误。
(我知道很多代码)game.php代码:
<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代码:
<?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');
?>
答案 0 :(得分:0)
你确定你想要&#34;或死(mysqli_error($ link))&#34;成为SQL的一部分,而不是PHP的一部分?