Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts

    why isnt this query working

    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 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

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,313
    Thanks
    4
    Thanked 207 Times in 204 Posts
    Code:
    $query2 = "UPDATE mail SET to='$newusername', from='$newusername' WHERE to='$username' AND from='$username'";
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    still nothing..
    the third query is actually working, i tested it this is strange

    PHP Code:

    /**
     * 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
    Last edited by Zangeel; 07-28-2008 at 07:12 PM.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,313
    Thanks
    4
    Thanked 207 Times in 204 Posts
    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:

    Code:
    $query2 = "UPDATE `mail` SET `to`='$newusername' AND `from`='$newusername' WHERE `to`='$username'` AND `from`='$username'";
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •