我相当确定我只犯了一个简单的错误,但我遇到了麻烦。基本上,每当有人填写正常表单时,他们输入的数据将提交到db表,稍后将发布在站点的另一页上。但是,这似乎不起作用。
如果可能的话,我只是想在正确的方向上帮助我实际做错了什么。
在此先感谢,我希望这篇文章不会太烦人。我是新来的:,)
PHP:
<?php
session_start();
include_once("connection.php");
if(isset($_POST['post'])) {
$match_name = strip_tags($_POST['match_name']);
$team1 = strip_tags($_POST['team1']);
$player1 = strip_tags($_POST['player1']);
$player2 = strip_tags($_POST['player2']);
$player3 = strip_tags($_POST['player3']);
$player4 = strip_tags($_POST['player4']);
$player5 = strip_tags($_POST['player5']);
$team2 = strip_tags($_POST['team2']);
$player6 = strip_tags($_POST['player6']);
$player7 = strip_tags($_POST['player7']);
$player8 = strip_tags($_POST['player8']);
$player9 = strip_tags($_POST['player9']);
$player10 = strip_tags($_POST['player10']);
$match_name = mysqli_real_escape_string($dbCon, $match_name);
$team1 = mysqli_real_escape_string($dbCon, $team1);
$player1 = mysqli_real_escape_string($dbCon, $player1);
$player2 = mysqli_real_escape_string($dbCon, $player2);
$player3 = mysqli_real_escape_string($dbCon, $player3);
$player4 = mysqli_real_escape_string($dbCon, $player4);
$player5 = mysqli_real_escape_string($dbCon, $player5);
$team2 = mysqli_real_escape_string($dbCon, $team2);
$player6 = mysqli_real_escape_string($dbCon, $player6);
$player7 = mysqli_real_escape_string($dbCon, $player7);
$player8 = mysqli_real_escape_string($dbCon, $player8);
$player9 = mysqli_real_escape_string($dbCon, $player9);
$player10 = mysqli_real_escape_string($dbCon, $player10);
$sql = "INSERT INTO `match` (match_name, team1, player1, player2, player3, player4, player5, team2, player6, player7, player8, player9, player10) VALUES ('$team1, '$player1', '$player2', '$player3', '$player4', '$player5', '$team2, '$player6', '$player7', '$player8', '$player9', '$player10')";
if($match_name == "") {
echo "You're missing a title for varible <strong>Match Title</strong> | <a href='post.php'>Go back</a>";
return;
}
if($team1 == "") {
echo "You're missing a title for varible <strong>Team 1 Name</strong> | <a href='post.php'>Go back</a>";
return;
}
if($team2 == "") {
echo "You're missing a title for varible <strong>Team 2 Name</strong>";
return;
}
mysqli_query($dbCon, $sql);
header("Location: index.php");
}
?>
答案 0 :(得分:0)
从@arkascha和@Jay Blanchard已经提到的所有事情向前迈进。
您在'
VALUES
和'$team1
'$team2
附近的SQL查询中遗漏了单引号$sql = "INSERT INTO `match` (match_name, team1, player1, player2, player3, player4, player5,
team2, player6, player7, player8, player9, player10)
VALUES ('$team1, '$player1', '$player2', '$player3', '$player4', '$player5',
'$team2, '$player6', '$player7', '$player8', '$player9', '$player10')";
:
而不是:
$sql = "INSERT INTO `match` (match_name, team1, player1, player2, player3, player4, player5,
team2, player6, player7, player8, player9, player10)
VALUES ('$team1', '$player1', '$player2', '$player3', '$player4', '$player5',
'$team2', '$player6', '$player7', '$player8', '$player9', '$player10')";
试试这个:
/controllers/front/CmsController.php