数据库没有更新“获取”PHP

时间:2012-06-26 09:19:06

标签: php mysql

我有一个页面查询将表设置为0或1.设置为1正在工作,但它不会设置回0.这是到目前为止的代码片段。任何人都可以看到什么是错的吗?

页:

<p><? if($_SESSION['user_level'] >= GUARDIAN_LEVEL) { if ($row_settings['profile_list'] == 0) {?> 
                    <a onclick='$.get("dos.php",{ cmd: "sprofile", setp:$("1").val(),id: "<?php echo $row_settings['id']; ?>" } ,function(data){ $("#msgp").html(data); });' href="javascript:void(0);">List</a>
                <?php } else if ($row_settings['profile_list'] == 1) {?>
                    <a onclick='$.get("dos.php",{ cmd: "sprofile", setp:$("0").val(),id: "<?php echo $row_settings['id']; ?>" } ,function(data){ $("#msgp").html(data); });' href="javascript:void(0);">Unlist</a>
                <?php } else {echo "N/A";}} else {echo "N/A";} ?></p>

更新代码:

if($get['cmd'] == 'sprofile')
{
mysql_query("update users set profile_list='$get[setp]' where id='$get[id]'");
echo "Profile Listing Changed";
//header("Location: $ret");  
// exit();
}

修改

更新代码:

if($_GET['cmd'] == 'sprofile')
{
$set = mysql_real_escape_string($_GET['setp']);
$id = mysql_real_escape_string($_GET['id']);
mysql_query("update users set profile_list='" . $set . "' where id='" . $id . "'");
echo "Profile Listing Changed";
//header("Location: $ret");  
// exit();
}

这会将其设置为0并显示正确的代码,但由于某种原因不会重新设置为1。

3 个答案:

答案 0 :(得分:2)

它是$_GET而不是$get

请至少使用

$param = mysql_real_escape_string($_GET['your_param_which_goes_to_building_mysql_query']);
$param2 = //similar..
$query = "update users set profile_list='$param1' where id='$param2'"

或者更好的是,使用prepared statements.

答案 1 :(得分:1)

更新代码:

  1. 使用$_GET代替$get(第1和第3行)

  2. 将此行用作第1行:

    if ($_GET['cmd'] == 'sprofile')
    
  3. 在第3行使用此行作为mysql_query:

    mysql_query("update users set profile_list='" . mysql_real_escape_string($_GET['setp']) . "' where id='" . mysql_real_escape_string($_GET['id']) . "';");
    

答案 2 :(得分:0)

setp:$("1").val()需要更改为setp: "1",因为它不应该从任何地方提取值

同时将$get更改为$_GET

相关问题