从PHP中获取$ _get的值

时间:2012-10-23 14:33:59

标签: php mysql phpmyadmin

为什么值不是0并插入到我的表中?这是我的代码:

<?php
    if ($_GET["subscribe"] == 0) 
        $Competition = $_GET["subscribe"];
        { 
            if (isset($_GET["subscribecontestant"]))
            {
                $sql1 = "INSERT INTO wedstrijdresultaten (WedstrijdID,DuifID,Username) VALUES (".$Competition.",".$_GET["subscribecontestant"].", '".$_SESSION['user']."')";
                $result1 = mysql_query($sql1);
            }
        }

3 个答案:

答案 0 :(得分:1)

错误放置{。首先{必须位于第一个if语句旁边

if ($_GET["subscribe"] == 0) {
 $Competition = $_GET["subscribe"];
if (isset($_GET["subscribecontestant"]))
{
 $sql1 = "INSERT INTO wedstrijdresultaten (WedstrijdID,DuifID,Username) VALUES (".$Competition.",".$_GET["subscribecontestant"].", '".$_SESSION['user']."')";
$result1 = mysql_query($sql1);
}
}

答案 1 :(得分:1)

您的代码中有一个小错误,其中包含if语句的括号。试试这个

if ($_GET["subscribe"] == 0) 
{
    $Competition = $_GET["subscribe"];

    if (isset($_GET["subscribecontestant"]))
    {
         $sql1 = "INSERT INTO wedstrijdresultaten (WedstrijdID,DuifID,Username) "
               . "VALUES (".$Competition."," 
               . $_GET["subscribecontestant"] . ", '" 
               . $_SESSION['user']."')";
         $result1 = mysql_query($sql1);
    }
}

答案 2 :(得分:-1)

可能存在多种原因导致其无法正常工作,其他答案中显示缺少大括号,而且我们也不知道您作为GET参数传递了什么。

但你应该忽略它们并在再做之前咨询http://www.phptherightway.com/#databases,你的例子对安全漏洞是敞开的。