<meta http-equiv="Content-Type" Content-Type:text/html; charset=utf-8" />
<?php
//自动跳转
//header("Content-Type:text/html; charset=utf-8");
$type=$_GET['type'];
$ID=$_GET[id];
$url="show_user.php";
$id=$_POST["id"];
//$title= $_POST["title"];
$password = $_POST["password"];
//date_default_timezone_set("Asia/Shanghai");//php.ini里加入了date.timezone这个选项,默认情况下是关闭的,也就是显示的时间(无论用什么php命令)都是格林威治标准时间,和北京时间正好差8个小时。//$time = date("Y-m-d H:i:s");//获得当前时间
$con = mysql_connect("localhost","root","123");
if(!$con)
{
die('连接数据库失败!'.mysql_error());
}
//header("Content-Type:text/html; charset=utf-8");
mysql_select_db("test", $con);
mysql_query("set names 'utf8'",$con);
echo "中国";
switch ($type)
{
case edit:
$sql = "update test set id='$id',pass='$password' where id='$id'";
    $qu = mysql_query($sql,$con);
if($qu)
{
echo  "<script language='javascript'>alert('编辑成功!');window.location='show_user.php'</script>";
exit;
}
break;
case add:
if(!mysql_query("INSERT INTO test (id,pass) values ('$id','$password')"))
{
die('数据插入失败!'.mysql_error());
}
else
{
echo "<script language='javascript'> alert('留言成功');window.location.href='$url'</script>";
exit;
}
break;
case dele:
$sql ="delete from test where id ='$ID'";
    $qu=mysql_query($sql,$con);
if($qu)
{
            echo "<script language='javascript'> alert('删除成功!'); window.location.href='show_user.php'</script>";
exit;
}
break;
}
/*
// 插入数据库*/
?>
为什么$_GET['type']取不到值

解决方案 »

  1.   

    这个$type=$_GET['type'];取不到值?
    那打印出你的url看看
      

  2.   

    是啊!就是$type=$_GET['type'];取不到值,我都使过了,就是获取不了。
      

  3.   

    var_dump($_GET);//试试。可能是环境问题
      

  4.   

    page.php?type=值是这样的吗,这样应该没问题啊
      

  5.   

    现在是取到了那个值,但是进不了switch循环,我是PHP菜鸟,望大侠们赐教。不胜感激
      

  6.   

    对,是page.php?type=值
    但是进不了那个循环。
      

  7.   

    你先说说你是怎么判断进不了switch的
      

  8.   

    switch ($type)
    {
    case "edit":
    //加引号