gpt4 book ai didi

PHP 未将提交的数据上传到数据库

转载 作者:行者123 更新时间:2023-11-29 21:58:52 25 4
gpt4 key购买 nike

我相当确定我只是犯了一个简单的错误,但我很难找到它。基本上,每当有人填写普通表单时,他们输入的数据都会提交到数据库表,然后发布到网站的另一个页面上。然而,这似乎不起作用。

如果可能的话,我只是想要一些关于我实际上做错了什么的正确方向的帮助。

预先感谢,我希望这篇文章不会太烦人。我是新来的:,)

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");
}
?>

最佳答案

从 @arkascha 和 @Jay Blanchard 已经提到的一切开始。

您在 SQL 查询中缺少 '$team1'$team2VALUES 附近的单引号 ' >:

而不是这个:

$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')";

关于PHP 未将提交的数据上传到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32871416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com