Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Thanked 0 Times in 0 Posts

    Problem create new mysql user w/ php code

    I'm new to every thing and trying to create new mysql user w/ php code as below, but always got error message "Error, insert query failed". Please, point out what I did wrong and how to fix it.

    PHP Code:
    or die(
    'Error, login db failed');
    mysql_select_db(mysql) or die('Error, open db failed');

    $query "INSERT INTO user(Host, User, Password) 
    VALUES('localhost', '$UserName', '$UserPass')"
    mysql_query($query) or die('Error, insert query failed');
    $query "FLUSH PRIVILEGES";
    mysql_query($query) or die('Error, flush query failed');
    And even tried it w/ this code
    PHP Code:
    $query "INSERT INTO user
    (Host, User, Password, Select_priv, Insert_priv, Update_priv) 
    VALUES ('localhost', $UserName, PASSWORD($UserPass), 'Y', 'Y', 'Y')"

    Already searched but not successful, so if this problem was posted here, please post the link here

    Edit: My info as follows:
    Windows XP Pro w/ SP2
    Apache 2.0.59 (Win32)
    PHP 5.1.6
    MySQL 5.1.12-bt

    Thanks a million
    Last edited by guelphdad; 01-30-2007 at 03:42 PM.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    St. Catharines, Ontario Canada
    Thanked 148 Times in 139 Posts
    change these:
    die('Error, open db failed');
    to something like this:
    die('Error, open db failed') . mysql_error();
    otherwise your error messages are not relevant. They don't actually tell you what the problem is.

    Also are you running this as the root user to mysql or another user privileged to add new users to your database?


    Posting Permissions

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