$ key = $ _ REQUEST [' key']不起作用

时间:2014-01-30 19:08:26

标签: php mysql request key

if (isset($_POST['cancel'])) {
    print("<script>location.href = 'task_led.php'</script>");
}
else if (isset($_POST['assign'])) {
    $atask = $_POST['task'];
    $table_task = $_POST['hid_task'];
    $key = $_REQUEST['key'];

    include 'sql.php';

    $SQL = " ALTER TABLE $table_task ADD $atask VARCHAR(255) NOT NULL";
    mysql_query($SQL);

    $SQL = "UPDATE info SET individ_task = '$atask' WHERE username = '$key'";
    mysql_query($SQL);


    $SQL = "INSERT INTO $table_task (`username`, $atask) VALUES ('$key',     'pending')";
    mysql_query($SQL);

    $SQL = "UPDATE info SET task_status_indi = 'pending' WHERE username = '$key'";
    mysql_query($SQL);

    mysql_close($db_handle);
    print("<script>location.href = 'task_led.php'</script>");
}
else{   

    $namekey = $_REQUEST['key'];
    $user = $_SESSION['username'];
    include 'sql.php';

    $SQL = "SELECT * FROM info WHERE username = '$user'";
    $result = mysql_query($SQL);
    while ($db_field = mysql_fetch_assoc($result)) {
        $grp = $db_field['groups'];//telephone_tech
        $tsk = $db_field['group_task'];//resolve_telephone
    }

    print("<div style='top:167; left:380; position:absolute; z-index:1;'>");
    print("<table border = '0' width = '370' bgcolor = 'white'>");
    print("<tr><td>$tsk</td></tr>");
    print("</table>");
    print("</div>");

    $SQL = "SELECT * FROM task_list WHERE taskname = '$tsk'";
    $result = mysql_query($SQL);
    while ($db_field = mysql_fetch_assoc($result)) {
        $dsc = $db_field['ds'];
    }

    print("<div style='top:200; left:250; position:absolute; z-index:1;'>");
    print("<font face='Broadway' size = '4'>Description:</font>");
    print("</div>");

    print("<div style='top:197; left:380; position:absolute; z-index:1;'>");
    print("<table border = '0' width = '370' bgcolor = 'white'>");
    print("<tr><td>$dsc</td></tr>");
    print("</table>");
    print("</div>");

    print("<div style='top:270; left:350; position:absolute; z-index:1;'>");
    print("<form name='add_form' method='post' action='add_task_led.php'>");
    print("<table border = '0' >");
    print("<tr><td><b>Name:</b></td>");
    print("<td><input name = 'uname' type = 'text' readonly = 'true' value = $namekey></td>");
    print("</tr>");
    print("<tr><td><b>Task:</b></td>");
    print("<td><input name = 'task' type = 'text' value = ''></td>");
    print("<input name = 'hid_task' type = 'hidden' value = $tsk>");
    print("</tr>"); 
    print("<tr>");
    print("<td align = 'right'><input name = 'reset' type = 'reset' value = 'reset'></td>");
    print("<td><input name = 'cancel' type = 'submit' value = 'cancel'>");
    print("<input name = 'assign' type = 'submit' value = 'ASSIGN'></td>");
    print("</tr>");
    print("</table>");
    print("</form>");
    print("</div>");
    mysql_close($db_handle);
}

我需要这方面的帮助它应该从nbproject/add_task_led.php?key=Marija这样的网址获取密钥,并将其放入$ key变量中,它似乎无法正常工作。当我直接在这个例子Marija而不是$key中输入名称时,它会更改数据库。我做错了吗?

1 个答案:

答案 0 :(得分:0)

用于测试目的

您是否可以使用我认为成功的以下代码设置测试表

请务必更改这些变量以适合您自己的变量,或者如下所示创建它们:

$table_task = "table_task"; // table name
$atask = "a_task"; // column name
$db_selected = mysql_select_db('db_name', $db); // db_name is your DB

HTML / PHP / SQL (表单操作设置为自己)

<?php
if (!empty($_REQUEST['key'])) {
  $key = $_REQUEST['key'];
  echo "key: ". $key. "\n";

$db = mysql_connect("host","username", "password");

$db_selected = mysql_select_db('db_name', $db);
if (!$db_selected) {
    die ('Can\'t use it : ' . mysql_error());
}

$table_task = "table_task";
$atask = "a_task";

$SQL = "INSERT INTO $table_task (`username`, $atask) VALUES ('$key', 'pending')";
mysql_query($SQL,$db);

// Used for my own testing purposes that you can comment out
// $SQL = "UPDATE $table_task SET a_task = 'pending_test' WHERE username = '$key'";
// mysql_query($SQL,$db);

}
?>

<!DOCTYPE html>
<html>
<head>
<body>

<form action="" method="get">
User: <input type="text" name="key" /><br />
<input type="submit" value="Send" />
</form>

</body>
</html>