0

I have a problem with this line of code - I have spent most of the day trying to get this resolved - can any one help? Here is the code that is causing the problem form what I can see! The problem is around the $qry...

$qry = "INSERT INTO members (employer, flat) VALUES('$employ','$address') WHERE     login='$_login'";
    $result = @mysql_query($qry);
    //Check whether the query was successful or not
    if($result) {
        header("location: member-profile.php");
        exit();
    }else {
        die("Query failed");
    }
?>

ERROR showing is: ( ! ) Notice: Undefined variable: _login in C:\wamp\www\123456\update.php on line 67

Thanks all.

4

2 回答 2

1

First variable $_login is Undefined, and second, it seems you are trying to update. You do not user WHERE for SELECT query.

If you want to update, it then your query should very much like this:

$sql = 'UPDATE table SET username = '$username' WHERE id = $_login;

variable $_login means, pretty much, the variable $_login is not defined. You must give it a value, before you can you expect it to work in your query.

于 2013-06-02T19:05:45.290 回答
0

INSERT doesn't allow the WHERE attribute, you need to use UPDATE instead

"UPDATE members SET employer='$employ', flat='$address' WHERE login='$_login'"

Be sure to prevent SQL injections and since mysql_* functions are deprecated you should switch to MySQLi or PDO

As for the error itself, you need to check if the variables are defined that you are using

if (!isSet($_login))
    // do sth
于 2013-06-02T19:05:34.247 回答