0

I have a problem with a mysql query. This is the code:

session_start ();
$db = mysql_connect('localhost', 'user', 'pw') or die(mysql_error());
mysql_select_db("wordpress_97") or die(mysql_error());

$names=mysql_query('set names utf8');

$tempnewpw = md5($tempnewpw);

$query = mysql_query("UPDATE wordpress_97.tUsers SET passwort = '$tempnewpw' WHERE tUsers.UserID = '$theuserid'") or die(mysql_error());

Yes I know that I shouldn't use the mysql_ functions but it's just testing..

And this is the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE wordpress_97.tUsers SET passwort = 'pwinmd5'' at line 1

I can't get away these Â...

The database shouldn't be the problem - other querys work without problems with the same structure.

Any ideas?

Thanks in advance

jumpskin
  • 31
  • 1
  • 6
  • 1
    what happens if you delete the whole line and write the query again, don't copy paste it. – Alex Andrei Dec 01 '15 at 12:06
  • Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Naruto Dec 01 '15 at 12:09
  • @AlexAndrei Thank you this worked, but now I see that the string gets encoded wrong - doesn't matter what I type in the string will be "d41d8cd98f00b204e9800998ecf8427e". – jumpskin Dec 01 '15 at 12:18
  • I added an answer for both your questions. – Alex Andrei Dec 01 '15 at 12:25

4 Answers4

1

Try this use mysql_set_charset

session_start (); # not use for the DB query's 
$db = mysql_connect('localhost', 'user', 'pw') or die(mysql_error());

mysql_set_charset('utf8',$db); # add this

$db_selected = mysql_select_db("wordpress_97",$db);
//$names=mysql_query('set names utf8'); --- remove 
if (!$db_selected) { 
    die ('Database access error : ' . mysql_error());
}
else{
    $tempnewpw = md5($tempnewpw);

    $query = mysql_query("UPDATE wordpress_97.tUsers SET passwort = '$tempnewpw' WHERE tUsers.UserID = '$theuserid'") 
    or die(mysql_error());  
}

In html

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
1

Delete the line and re-type it.
Most likely those are characters carried over from copy-pasting.

Regarding your second question, d41d8cd98f00b204e9800998ecf8427e is the md5 hash of null or nothing, a zero-length stream of characters.

On this line

$tempnewpw = md5($tempnewpw);

Make sure that $tempnewpw exists and has a value, I should suggest also that you use different variables instead of over-writing them.

Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
  • The re-typing of the query helped! And I've seen, that my form submit function had a little mistake in it -> I wrote metod="post" instead of method... Thanks for your help with the query! – jumpskin Dec 01 '15 at 12:33
0

you can try to add this line in your html head tag:

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
Gouda Elalfy
  • 6,888
  • 1
  • 26
  • 38
0

Don't use Word for editing. It introduces funny characters such as hex A0, which through some conversions becomes  (A-hat and a space), as seen in your text.

I hope you don't have any accented letters; I suspect they have been mangled by other things -- such as failure to be consistent in CHARACTER SET.

Rick James
  • 135,179
  • 13
  • 127
  • 222