...

View Full Version : Problem create new mysql user w/ php code



yfastud
01-29-2007, 04:15 PM
Hi,
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
$connect = mysql_pconnect('localhost', $AdminName, $AdminPass)
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
[

$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

guelphdad
01-30-2007, 03:43 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum