所以我有这个错误,我无法弄清楚什么是错的:
Fatal error: Call to a member function bind_param() on a non-object in /home1/tony1964/public_html/2v2tournaments/action.php
register.php:
<?php
if (isset($_GET['type']) && $_GET['type'] === "2") {
echo '<form class="register_form" action="action.php?do=reg_type_2" method="post"><br>';
echo 'Team Name*: <input type="text" name="teamname" required /><br>';
echo 'Team Region*: <input type="text" name="teamregion" maxlength="4" required /><br>';
echo 'Team Leader*: <input type="text" name="teamleader" maxlength="16" required /><br>';
echo 'Team Member[1]*: <input type="text" name="teammember" maxlength="16" required /><br>';
echo '<input name="register_submit" type="submit" value="Register" /><br>';
echo '</form><br>';
}
else if (isset($_GET['type']) && $_GET['type'] === "3") {
echo '<form class="register_form" action="action.php?do=reg_type_3" method="post"><br>';
echo 'Team Name*: <input type="text" name="teamname" required /><br>';
echo 'Team Region*: <input type="text" name="teamregion" maxlength="4" required /><br>';
echo 'Team Leader*: <input type="text" name="teamleader" maxlength="16" required /><br>';
echo 'Team Member[1]*: <input type="text" name="teammember1" maxlength="16" required /><br>';
echo 'Team Member[2]*: <input type="text" name="teammember2" maxlength="16" required /><br>';
echo '<input name="register_submit" type="submit" value="Register" /><br>';
echo '</form><br>';
}
else if (isset($_GET['type']) && $_GET['type'] === "5") {
echo '<form class="register_form" action="action.php?do=reg_type_5" method="post"><br>';
echo 'Team Name*: <input type="text" name="teamname" required /><br>';
echo 'Team Region*: <input type="text" name="teamregion" maxlength="4" required /><br>';
echo 'Team Leader*: <input type="text" name="teamleader" maxlength="16" required /><br>';
echo 'Team Member[1]*: <input type="text" name="teammember1" maxlength="16" required /><br>';
echo 'Team Member[2]*: <input type="text" name="teammember2" maxlength="16" required /><br>';
echo 'Team Member[3]*: <input type="text" name="teammember3" maxlength="16" required /><br>';
echo 'Team Member[4]*: <input type="text" name="teammember4" maxlength="16" required /><br>';
echo '<input name="register_submit" type="submit" value="Register" /><br>';
echo '</form><br>';
}
else {echo "Error: Incorrect Reg_type";}
?>
action.php的:
<?php
$con=new mysqli("192.185.4.166","myName","myPassword","myDatabase");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
$teamname = $_POST["teamname"];
$teamregion = $_POST["teamregion"];
$teamleader = $_POST["teamleader"];
$teammember = $_POST["teammember"];
$wins = 0;
$loses = 0;
$stmt = $con->prepare("INSERT INTO `team_type_2` (`teamname`,`region`,`teamleader`,`teammember`,`wins`,`loses`) VALUES (?,?,?,?,?,?)");
$stmt->bind_param('ssssii', $teamname, $teamregion, $teamleader, $teammember, $wins, $loses);
$stmt->execute();
$stmt->close();
}
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_3") {
$teamname = $_POST["teamname"];
$teamregion = $_POST["teamregion"];
$teamleader = $_POST["teamleader"];
$teammember1 = $_POST["teammember1"];
$teammember2 = $_POST["teammember2"];
$wins = 0;
$loses = 0;
$stmt = $con->prepare("INSERT INTO `team_type_3` (`teamname`,`region`,`teamleader`,`teammember1`,`teammember2`,`wins`,`loses`) VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param('ssssii', $teamname, $teamregion, $teamleader, $teammember1, $teammember2, $wins, $loses);
$stmt->execute();
$stmt->close();
}
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_5") {
$teamname = $_POST["teamname"];
$teamregion = $_POST["teamregion"];
$teamleader = $_POST["teamleader"];
$teammember1 = $_POST["teammember1"];
$teammember2 = $_POST["teammember2"];
$teammember3 = $_POST["teammember3"];
$teammember4 = $_POST["teammember4"];
$wins = 0;
$loses = 0;
$stmt = $con->prepare("INSERT INTO `team_type_5` (`teamname`,`region`,`teamleader`,`teammember1`,`teammember2`,`teammember3`,`teammember4`,`wins`,`loses`) VALUES (?,?,?,?,?,?,?,?,?)");
$stmt->bind_param('ssssii', $teamname, $teamregion, $teamleader, $teammember1, $teammember2, $teammember3, $teammember4, $wins, $loses);
$stmt->execute();
$stmt->close();
}
else {echo "Error: Unknown, Contact Admin";}
?>
有人有任何想法吗?
答案 0 :(得分:1)
您的某些准备语句中有错误。
请将您的3 $stmt = $con->prepare(...)
更改为:
if (!($stmt = $con->prepare("....")) || !is_object($stmt)) {
die( "Error preparing: (" .$con->errno . ") " . $con->error);
}