简体   繁体   中英

PHP Not uploading submitted data to the db

I'm fairly sure I've only made a simple mistake, yet I am having troubles finding it. Basically, whenever someone fills in a normal form, the data they enter is submitted to the db table, to be later posted on another page of the site. However, that does not seem to be working.

If possible, I'd just like some help in the right direction about what I've actually done wrong.

Thanks in advance, I hope this post isn't too annoying. I'm new here :,)

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

Moving forward from everything @arkascha and @Jay Blanchard already mentioned.

You missing the single quotes ' in your SQL query near VALUES of '$team1 and '$team2 :

Instead of this:

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

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM