Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果没有发布,如何不更新_Php - Fatal编程技术网

Php 如果没有发布,如何不更新

Php 如果没有发布,如何不更新,php,Php,我有以下标准形式: 表格: <div id="ajaXmsg"></div> <form method="post" accept-charset="UTF-8" action="#" class="formee" id="useredit"/> <input type="hidden" name="p" id="p" value=""> <input type="hidden" name="retype" i

我有以下标准形式:

表格:

                <div id="ajaXmsg"></div>
<form method="post" accept-charset="UTF-8" action="#" class="formee" id="useredit"/>
<input type="hidden" name="p" id="p" value="">
<input type="hidden" name="retype" id="retype" value="">
<input type="hidden" name="oldpass" id="oldpass" value="">
<?php $n->generateFormFields(); ?>
<table style="margin:0 auto;width:100%">
        <tr>

            <td style="font-weight:bold;">שינוי שם משתמש (נוכחי <span style="color:blue;"><?php echo $user['username']; ?></span>) ל - </td>
            <td>
                <input style="height:30px;width:250px;padding:0;line-height:30px;" type="text" id="uname" name="uname" value="" placeholder="<?php echo $user['username']; ?>" class="inplaceError" /><span class="clear" id="uname_error"></span>
            </td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי שם פרטי (נוכחי <span style="color:blue;"><?php echo $user['user_fname']; ?></span>) ל - </td>
            <td><input type="text" id="fname" value="" placeholder="<?php echo $user['user_fname']; ?>" name="fname" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /><span class="clear" id="fname_error"></span></td>
        </tr>
                <tr>
            <td style="font-weight:bold;">
שינוי שם משפחה(נוכחי <span style="color:blue;"><?php echo $user['user_lname']; ?></span>) ל - </td>
            <td><input type="text" id="lname" value="" placeholder="<?php echo $user['user_lname']; ?>" name="fname" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /><span class="clear" id="lname_error"></span></td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי דוא"ל (נוכחי <span style="color:blue;"><?php echo $user['useremail']; ?></span>) ל - </td>
            <td><input type="text" id="email" value="" placeholder="<?php echo $user['useremail']; ?>" name="email" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /> <span class="clear" id="email_error"></span></td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי סיסמא:</td>
            <td><input type="password" id="password"  name="password" style="height:30px;width:250px;padding:0;"/><span style="color:black;font-weight:bold;" class="inplaceError"> *הקש שנית: </span><input type="password" id="newpass"  onclick="this.value='';" name="newpass" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;"/><span class="clear" id="password_error"></span><span class="clear" id="newpass_error"></span></td>
        </tr>
<tr>
            <td style="font-weight:bold;">*סיסמא נוכחית:</td>
            <td><input type="password" id="oldpassinp" name="oldpassinp" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;"/> 
            <span class="clear" id="oldpassinp_error" ></span>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><a href="#" id="submitedit" onClick="return false;" style="text-decoration:none;"><div class="editbut">עדכן</div></a></td>
        </tr>
    </table>

</form>
        if ($update_stmt = $func->mysqli->prepare(

        "UPDATE users SET 
           username = ?,
           useremail = ?,
           user_fname = ?,
           user_lname = ?,
           timestamp = ?,
           password = ?, 
           salt = ? 
           WHERE userid = '".$user_data['userid']."'"

        ))
        {

        $update_stmt->bind_param('sssssss',$uname, $useremail,$user_fname,$user_lname,$timestamp, $password, $random_salt);
        // Execute the prepared query.
        $update_stmt->execute();
            $return = array('form' => true,'key' => $json['2'], 'nonce' => $json['1']);
             header('content-type: application/json; charset=utf-8');
             echo json_encode($return);

        }
        else
        {
               $return = array('form' => false,'key' => $json['2'], 'nonce' => $json['1']);
                header('content-type: application/json; charset=utf-8');
               echo json_encode($return);

        }
 username=(CASE username WHEN '".empty($_POST['uname'])."' THEN username ELSE ? END),
现在我通过ajax发送,所有工作都完美执行一件事:

即使字段(post)为空,它也会将字段更新为空,这不好,我需要保留相同的字段而不进行更新,我的意思是,如果字段为空,则不更新所有特定列,我该怎么做

例如:

如果post用户名为空,则不更新所有用户名列

提前感谢,如果需要,将添加更多代码

编辑1:

                <div id="ajaXmsg"></div>
<form method="post" accept-charset="UTF-8" action="#" class="formee" id="useredit"/>
<input type="hidden" name="p" id="p" value="">
<input type="hidden" name="retype" id="retype" value="">
<input type="hidden" name="oldpass" id="oldpass" value="">
<?php $n->generateFormFields(); ?>
<table style="margin:0 auto;width:100%">
        <tr>

            <td style="font-weight:bold;">שינוי שם משתמש (נוכחי <span style="color:blue;"><?php echo $user['username']; ?></span>) ל - </td>
            <td>
                <input style="height:30px;width:250px;padding:0;line-height:30px;" type="text" id="uname" name="uname" value="" placeholder="<?php echo $user['username']; ?>" class="inplaceError" /><span class="clear" id="uname_error"></span>
            </td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי שם פרטי (נוכחי <span style="color:blue;"><?php echo $user['user_fname']; ?></span>) ל - </td>
            <td><input type="text" id="fname" value="" placeholder="<?php echo $user['user_fname']; ?>" name="fname" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /><span class="clear" id="fname_error"></span></td>
        </tr>
                <tr>
            <td style="font-weight:bold;">
שינוי שם משפחה(נוכחי <span style="color:blue;"><?php echo $user['user_lname']; ?></span>) ל - </td>
            <td><input type="text" id="lname" value="" placeholder="<?php echo $user['user_lname']; ?>" name="fname" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /><span class="clear" id="lname_error"></span></td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי דוא"ל (נוכחי <span style="color:blue;"><?php echo $user['useremail']; ?></span>) ל - </td>
            <td><input type="text" id="email" value="" placeholder="<?php echo $user['useremail']; ?>" name="email" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;" /> <span class="clear" id="email_error"></span></td>
        </tr>
        <tr>
            <td style="font-weight:bold;">שינוי סיסמא:</td>
            <td><input type="password" id="password"  name="password" style="height:30px;width:250px;padding:0;"/><span style="color:black;font-weight:bold;" class="inplaceError"> *הקש שנית: </span><input type="password" id="newpass"  onclick="this.value='';" name="newpass" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;"/><span class="clear" id="password_error"></span><span class="clear" id="newpass_error"></span></td>
        </tr>
<tr>
            <td style="font-weight:bold;">*סיסמא נוכחית:</td>
            <td><input type="password" id="oldpassinp" name="oldpassinp" class="inplaceError" style="height:30px;width:250px;padding:0;line-height:30px;"/> 
            <span class="clear" id="oldpassinp_error" ></span>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><a href="#" id="submitedit" onClick="return false;" style="text-decoration:none;"><div class="editbut">עדכן</div></a></td>
        </tr>
    </table>

</form>
        if ($update_stmt = $func->mysqli->prepare(

        "UPDATE users SET 
           username = ?,
           useremail = ?,
           user_fname = ?,
           user_lname = ?,
           timestamp = ?,
           password = ?, 
           salt = ? 
           WHERE userid = '".$user_data['userid']."'"

        ))
        {

        $update_stmt->bind_param('sssssss',$uname, $useremail,$user_fname,$user_lname,$timestamp, $password, $random_salt);
        // Execute the prepared query.
        $update_stmt->execute();
            $return = array('form' => true,'key' => $json['2'], 'nonce' => $json['1']);
             header('content-type: application/json; charset=utf-8');
             echo json_encode($return);

        }
        else
        {
               $return = array('form' => false,'key' => $json['2'], 'nonce' => $json['1']);
                header('content-type: application/json; charset=utf-8');
               echo json_encode($return);

        }
 username=(CASE username WHEN '".empty($_POST['uname'])."' THEN username ELSE ? END),
这就是你的意思吗?

在查询中使用mysql

UPDATE tablename
   SET column1 = CASE WHEN  phppostvalue = '' THEN column1 ELSE ? END
WHERE someconditions
查询中可以有多个条件,例如

UPDATE tablename
   SET column1 = CASE WHEN  phppostvalue = '' THEN column1 ELSE ? END,
   SET column1 = CASE WHEN  phppostvalue = '' THEN column1 ELSE ? END,
   SET column1 = CASE WHEN  phppostvalue = '' THEN column1 ELSE ? END
WHERE someconditions
使用PHP:

$buildQuery = 'UPDATE user SET ';
foreach($_POST as $key => $values) {
    if($values != '') {
        $buildQuery .= "{$key} = ? ";
        // Bind values
        $paramList  .= "{$values},";
    }
}
$buildQuery .= "WHERE userid = '".$user_data['userid']."'";
//remove last comma
trim($paramList, ',');

我没有测试过这个,但是像这样的东西应该可以。例如,我没有检查未定义的变量…

使用
if(isset($\u POST)&&$\u POST!='''{your update code here}
…我有它,这不是问题,问题在update函数中,即使没有发布,它也会更新为“”(空)。嗨,我对mysql查询的I'v编辑我的问题没有那么强,你能看看你的意思吗?谢谢