0

我想我现在真的很接近了 - 不再有令人讨厌的橙色框有错误 - 我现在唯一能看到的问题是,一旦我更新了表格(在

$qry = "UPDATE 'members' ('employer', 'flat') WHERE login='$login_name' VALUES ". " ('$employ', $address')";

) 我得到消息"No rows updated"回显到屏幕上!

任何想法是什么问题?谢谢。

<?php
    //Start session
    session_start();
    $_SESSION['SESS_LOGIN'];
    //Include database connection details
    require_once('config.php');

//Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    //Sanitize the POST values
    $employ = clean($_POST['employer']);
    $address = clean($_POST['flat']);



?>



<?Php
//Insert employer and address into database row for logged in user.    
$login_name = $_POST['login_name'] ;
$qry = "UPDATE 'members' ('employer', 'flat') WHERE login='$login_name' VALUES ". "     ('$employ', $address')" ;



    $result = @mysql_query($link, $qry);
    //Check whether the query was successful or not
    if(!$result) {
        echo "No rows updated";
        exit();
    }else {
        echo "Success";
    }
?>
4

2 回答 2

2

不要使用VALUES,使用SET

"UPDATE `members` SET `employer` = '".$employ."', `flat` = '".$address."' WHERE `login`='".$login_name."'"
于 2013-06-05T19:29:22.913 回答
0

首先,@如果您正在寻找代码中的问题,则不应使用运算符来抑制错误消息。此外,您使用了错误的括号('而不是`)。您的其余代码看起来不错。也许你需要给我们一些关于数据库结构的信息,否则

于 2013-06-05T19:32:31.223 回答