0

I am trying to update the password of the table 'nbk6_user'.

when the script is launched I get the error: "Fehler"

Am I doing the mysql_query right?

Can anybody help me please?

<?php
include 'conf.php';
$connection = mysql_connect("****", "****", "****");
mysql_select_db($datenbank);
session_start();

if(!isset($_SESSION["name"]))
{
    die("Für diese Seite musst du dich zuerst anmelden!");
}
$name = $_SESSION["name"];

$pw1 = $_POST["pw1"];
$pw2 = $_POST["pw2"];

$pw1 = trim($pw1);
$pw2 = trim($pw2);

if($pw1 == "")
{
die("Kein Passwort gesetzt.");
}

if($pw1 == $pw2)
{
    $query = mysql_query("UPDATE nbk6_user SET password='$pw1', WHERE name='$name'");
    if(!$query)
    {   
        echo "Fehler";
    }
}
else
{
    echo "Die Passwörter stimmen nicht überein";
}
?>
1
  • remove the comma before where Commented Aug 2, 2012 at 13:51

5 Answers 5

1

try see the error with mysql_error, but I think that u are putting "," after password='$pw1' I think so just try it

Sign up to request clarification or add additional context in comments.

Comments

0

You shouldn't have a coma after SET and it's best to avoid inserting the variables inside a string, when dealing with MySQL queries (or any strings really, it's bad practice).

Try:

$query = mysql_query("UPDATE nbk6_user SET password='".$pw1."' WHERE name='".$name."'");
if(!$query)
{   
    mysql_error();
    echo "Fehler";
}

if the changed query doesn't fix it mysql_error() will explain where the issue is.

Comments

0

You have a dangling comma:

... SET password='$pw1', WHERE ...
                       ^---

Comments

0

Error in the query use this

$query = mysql_query("UPDATE nbk6_user SET password='".$pw1."' WHERE name='".$name."'");

Also read the first answer here, this will brief you why you should not use mysql_* and use mysqli and PDO , taking care of sql injections.

4 Comments

then I get this error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/.sites/26/site2378/web/nbk6/changepw.php on line 57 (line 57 is the mysql_query - line)
I think you are missing the quotes in the end of query, check it once mysql_query("UPDATE nbk6_user SET password="'.$pw1.'" WHERE name="'.$name.'" ")
-1. Changing string concatenation methods does NOTHING. $x = "a$b" is functionally identical to $x = 'a' . $b. All you've done is rearrange deck chairs on the titanic.
you do need quotes around string type variables in sql, so to add them you need to concatenate multiple strings in php.
0

At first :

session_start(); must be the first line in your code.

Then

 $query = mysql_query("UPDATE nbk6_user SET password='$pw1', WHERE name='$name'");
must be
$pw1=md5($pw1);
 $query = mysql_query("UPDATE nbk6_user SET password='$pw1' WHERE name='$name'");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.