Php 协助准备声明

Php 协助准备声明,php,sql,mysqli,Php,Sql,Mysqli,编辑:错误:列计数与第1行的值计数不匹配 我已经尝试了很长一段时间(几小时,甚至几天,多次尝试)来设置一个准备好的语句来阻止SQL注入攻击,但我就是无法控制它。有人能帮我解决这个问题并指出我哪里出了问题吗?我想学习如何做到这一点,以便我可以在未来使用它,但以这种速度,我永远不会得到它 表格: <form action="php/xaddPlayerSkills.php" method="post"> <!--player skills form

编辑:错误:列计数与第1行的值计数不匹配

我已经尝试了很长一段时间(几小时,甚至几天,多次尝试)来设置一个准备好的语句来阻止SQL注入攻击,但我就是无法控制它。有人能帮我解决这个问题并指出我哪里出了问题吗?我想学习如何做到这一点,以便我可以在未来使用它,但以这种速度,我永远不会得到它

表格:

            <form action="php/xaddPlayerSkills.php" method="post">      <!--player skills form to be added-->
        playerID  : <input type="int" name="playerID" value="<?php  echo $playerID ?>" readonly> </td></tr>
        SquadID: <input type="text" name="squadID"><br>
        Passing: <input type="text" name="passing" value="Standard: Spin: Pop:"><br>
        Tackling: <input type="text" name="tackling" value="Front: Rear: Side: Scrabble:"><br>
        Kicking: <input type="text" name="kicking" value="Drop: Punt: Grubber: Goal:"><br>

        Comments: <input type="text" name="comments"><br>
        Date: <input type="date" name="date"><br>

        <input type="Submit" value = "Add ">
        </form>

代码中有几个问题,但最值得注意的是查询中的占位符,它应该是
,而不是
值(playerID、squadID、pass、attacking、kicking…
),并且您正在使用类型double,
d
,来描述日期:

$con=mysqli_connect($host,$user,$userpass,$schema);
// Error handling: If connection fails, the next lines of code will error handle the problem and if possible, give a reason why.
if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

$result= "INSERT INTO playerSkills VALUES (?,?,?,?,?,?,?)";

$insert=$con->prepare($result);
$insert->bind_param("issssss",$playerID,$squadID,$passing,$tackling,$kicking,$comments,$date); // change d to s for the date
$insert->execute();
$insert->close();
阅读以了解有关数据类型的说明。
d
表示双精度,而不是日期。然后查看示例,了解应使用哪些占位符


编辑:注意-如果其中一列是自动递增列,则不应将其包含在查询中,因为数据库将负责确保该列正确更新。

您的bind语句中似乎有一个额外的
$sheetNo
。除此之外,您还应添加问题所在。@jeroen th感谢您指出这一点,但不幸的是,我仍然收到一个错误您收到了什么错误?@mi6crazyheart我现在有一个新的错误,但至少是反馈。我将编辑我的帖子并将其放在顶部。感谢您的评论。不能说这是错误还是错误,但在您的
绑定参数(“ISSSSD”)中
1st参数应该是一个整数,但在您的情况下,它可能是字符串。您能检查一下吗?
                  $con=mysqli_connect($host,$user,$userpass,$schema);
                  // Error handling: If connection fails, the next lines of code will error handle the problem and if possible, give a reason why.
             if (mysqli_connect_errno())
               {
               echo "Failed to connect to MySQL: " . mysqli_connect_error();
               }



            $result= mysqli_query($con,"INSERT INTO playerSkills VALUES (playerID,squadID,passing,tackling,kicking,comments,date)");

            $insert=$con->prepare($result);
            $insert->bind_param("isssssd",$playerID,$squadID,$passing,$tackling,$kicking,$comments,$date);
            $insert->execute();
            $insert->close();

        mysqli_close($con);
        header ("location: ../databasePlayers.php");
        ?>
$con=mysqli_connect($host,$user,$userpass,$schema);
// Error handling: If connection fails, the next lines of code will error handle the problem and if possible, give a reason why.
if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

$result= "INSERT INTO playerSkills VALUES (?,?,?,?,?,?,?)";

$insert=$con->prepare($result);
$insert->bind_param("issssss",$playerID,$squadID,$passing,$tackling,$kicking,$comments,$date); // change d to s for the date
$insert->execute();
$insert->close();