...

View Full Version : why isnt this query working



Zangeel
07-28-2008, 05:30 PM
i have a script, that ustilizes a pm system.
im making a mod for it, to change user names. and i need to update multiple querys to do it

here's the whole code



<?php

/************************
*
* CREATED BY WEBMASTERX
*
************************/


if(isset($_POST['submit'])) {

$username = mysql_real_escape_string($_POST['username']);
$newusername = mysql_real_escape_string($_POST['newusername']);

/**
* Updateing user table
* */
$query = "UPDATE user SET user='$newusername' WHERE user='$username'";

/**
* Updating Mail
* */
$query2 = "UPDATE mail SET to='$newusername', from='$newusername' WHERE to='$username', from='$username'";

/**
* Updating Friends
* */

$query3 = "UPDATE friends SET user='$newusername', friend='$newusername' WHERE user='$username', friend='$username'";


/**
* Checking for errors
* */

$check = mysql_query("SELECT user FROM phpfox_user WHERE user='$username'");
$check2 = mysql_query("SELECT user FROM phpfox_user WHERE user='$newusername'");

/**
* Checking & Executing
* */

if(mysql_num_rows($check) == 0) {

echo "Dudddee " .$username. " is not even a REAL user";

} elseif (mysql_num_rows($check2) == 1) {

echo "Sorry, that's already a username, you can't change " .$username. " to " .$newusername;

}

elseif ((empty($username)) || empty($newusername)) {

echo "Fill in both fields, loser!";
} else {
echo "CHANGED <br />" . $username ." was changed to <a href=/$newusername>" . $newusername ."</a>";
mysql_query($query) or die("Error in changin user table");
mysql_query($query2) or die ("Error in changing mail tables");
mysql_query($query3) or die ("Error in changing friends tables");

}
}

?>


it dies at the second query and probably will do the same on the third. what am i doing wrong

djm0219
07-28-2008, 05:53 PM
$query2 = "UPDATE mail SET to='$newusername', from='$newusername' WHERE to='$username' AND from='$username'";

Zangeel
07-28-2008, 06:09 PM
still nothing..
the third query is actually working, i tested it this is strange




/**
* Updating Mail
* */

$query2 = "UPDATE mail SET to='$newusername' AND from='$newusername' WHERE to='$username'` AND from='$username'";

/**
* Updating Friends
* */

$query3 ="UPDATE friends SET user='$newusername' AND friend='$newusername' WHERE user='$username' AND user='$username'";



2nd one dies
3rd one works

djm0219
07-28-2008, 06:19 PM
What is the error that MySQL is reporting when it fails?

Column names such as to and from are likely going to cause you problems at some point so I've found it to be good practice to always surround table and column names with backticks (`). So try it this way:


$query2 = "UPDATE `mail` SET `to`='$newusername' AND `from`='$newusername' WHERE `to`='$username'` AND `from`='$username'";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum