try:
<?php
define( "DATABASE_SERVER", "blah" );
define( "DATABASE_USERNAME", "blah" );
define( "DATABASE_PASSWORD", "blah" );
define( "DATABASE_NAME", "blah" );
//connect to the database
$con = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
mysql_select_db( DATABASE_NAME );
$sql = 'SELECT * FROM `users`';
$result = mysql_query($sql,$con) or die ('Error: '.mysql_error());
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$hPassword = hash ( sha256, $row['password']);
$query = "INSERT INTO new_users (username, password)
VALUES('".$row['username']."','$hPassword')";
$result = mysql_query($query);
}
?>
kkeith29
Nearly a Posting Virtuoso
1,353 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
Why the $result = mysql_query($query); on the fourth last line? You don't need the $result = on that line as the mysql_query will return TRUE on success. You are then treating this as a MySQL result resource in mysql_fetch_array($result) (because the expression in the why loop is executed every time the while loop tries to run).
See http://au.php.net/manual/en/function.mysql-query.php
You should get rid of the $result = assignment (or use a different variable name if it is needed) and it should work.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
wow, i can't believe i missed that. yes humbug is right. when you rename that variable it will work fine.
kkeith29
Nearly a Posting Virtuoso
1,353 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194