更新mysql表时出错

时间:2013-11-08 16:23:15

标签: php mysql

这里我试图显示成员的记录并尝试编辑细节。 首先,我将数据库中的详细信息提取到文本框中,然后,当我按下提交按钮时..应该更新更新的条目,并保留未更新的文本框的原始值。

这是代码: -

第一个是 editmember.php

<?php
session_start();
include 'dbconnector.php';
$receivedusername=$_REQUEST['username'];
$parentusername=$_SESSION['username'];
$_SESSION['cusername']=$receivedusername;
//check session
if((isset($_SESSION['logged'])) && ($_SESSION['logged']==1))
{
    //now map the user to it's parent account
    $query="select * from master_member where parentusername = '" . $parentusername . "' and currentusername = '" . $receivedusername . "'";
    $result=mysql_query($query,$db) or die (mysql_error($db));
    if(mysql_num_rows($result) > 0)
    {
        $row=mysql_fetch_assoc($result);
        //account mapped, green signal to proceed
        ?>
        <form action="memberaction.php?action=edit" method="post">
        <table>
        <tr>
        <td>Username : <input type="text" name="usrnm" value="<?php echo ($row['currentusername']); ?>" /></td>
        </tr>
        <tr>
        <td>Email : <input type="text" name="eml" value="<?php echo ($row['currentemail']); ?>" /></td>
        </tr>
        <tr>
        <td><input type="submit" name="submit" value="submit"></td>
        </tr>
        </table>
        </form>
        <?php 
    }
    else
    {
        echo "You aren't authorized to perform this task, redirecting.";
        header('refresh:2;URL=members.php');
        exit();
    }
}
else
{
    header('Location:login.php');
    exit();
}
?>

memberaction.php

case 'update':
        $memberusername=$_SESSION['cusername'];//username of the member, whose account is to be edited.
        $parentusername=$_SESSION['username'];//username of the parent.
        //since the account is already matched to the parent account before, we do not need to do it again.
        //get the field value
            $usrnm=(isset($_POST['usrnm'])) ? $_POST['usrnm'] : '';
            $eml=(isset($_POST['eml'])) ? $_POST['eml'] : '';
            $query="update master_member set currentusername = '" . $usrnm . "' and currentemail = '" . $eml . "' where parentusername = '" . $parentusername . "' and currentusername = '" . $memberusername . "'";
            $result=mysql_query($query,$db) or die (mysql_error($db));
            if($result)
            {
                echo "updated";
                header('refresh:2;URL=members.php');
                exit();
            }
            else
            {
                echo "Errors";
            }

        break;

点击提交按钮后,它显示已成功更新,但数据库中没有发生任何更改。 我在做什么可能的错误?

我的数据库结构如下: -

http://sqlfiddle.com/#!2/969c54/2

0 个答案:

没有答案