php实现修改信息,可是数据库的信息没有变化

 确认的时候,提示修改成功,可是数据库的信息没有变化

<?php

$username = trim($_POST['username']);
$pw = trim($_POST['pw']);
$cpw = trim($_POST['cpw']);
$email =$_POST['email'];
$sex = $_POST['sex'];
$fav = @implode(",",$_POST['fav']);

//进行必要的验证
if (!strlen($username)){
    echo"<script>alert('用户名必须要填写');history.back();</script>";
    exit;
}else{
    if (!preg_match('/^[a-zA-Z0-9]{3,10}$/',$username)){
        echo"<script>alert('用户名必填,且只能由大小字符和数字构成,长度为3到10个字符!');history.back();</script>";
        exit;
    }
}

if (!empty($pw)){
    if ($pw <> $cpw){
        echo"<script>alert('密码和确认密码都必须要相同');history.back();</script>";
        exit;
    }else {
        if (!preg_match('/^[a-zA-Z0-9_*]{6,10}$/', $pw)) {
            echo "<script>alert('密码必填,且只能大小写字符和数字,以及*、_构成,长度为6-10个字符!');history.back();</script>";
            exit;
        }
    }
}

if (!empty($email)) {
    if (!preg_match('/^[a-zA-Z0-9_\-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/', $email)) {
        echo "<script>alert('邮件地址格式不正确!');history.back();</script>";
        exit;
    }
}

$conn = mysqli_connect("localhost","root","20031022","member");

//第二步,设置字符串
mysqli_query($conn,"set names utf8");


if($pw){
    $sql = "update info set pw = '".md5($pw)."' ,email = '.$email.',sex = '.$sex.' ,fav = '.$fav.' where username ='.$username.'";
    $url = 'logout.php';
}else{
    $sql = "update info set username ='.$username.', email = '.$email.',sex = '.$sex.' ,fav = '.$fav.' where username ='.$username.'";
    $url ='index.php';
}
$result = mysqli_query($conn,$sql);

if ($result){
    echo "<script>alert('更新个人资料成功!');location.href='$url';</script>";
}else{
    echo "<script>alert('更新个人资料失败!');history.back();</script>";
}

?>

看看把sql语句拿去phpmyadmin能不能成功运行

//php语法没有理解好,单引号中的内容,PHP不解析,
$sql = "update info set pw = '".md5($pw)."' ,email = '.$email.',sex = '.$sex.' ,fav = '.$fav.' where username ='.$username.'";
修改为
$sql = "update info set pw = '".md5($pw)."' ,email = '".$email."',sex = '".$sex."' ,fav = '".$fav."' where username ='".$username."'";

我之前数据表ID 是Gid 修改数据不成功,将数据表Gid改为 id修改数据就成功了。有人知道这是为什么吗?