DeveloperSide.NET Forums
December 14, 2019, 03:55:06 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Problem create new mysql user w/ php code  (Read 8418 times)
0 Members and 1 Guest are viewing this topic.
yfastud
Customer, Basic Support
Jr. Member
*****
Posts: 36


View Profile
« on: January 29, 2007, 07:01:11 PM »

Hi,
I'm new to mysql and php and coding, so on 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. BTW, don't yell at me if this forums doesn't support coding, and yes, I do know that I can use phpmyadmin but just want to practice on coding.

<?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')";

Thanks a million
Logged
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #1 on: January 29, 2007, 07:20:17 PM »

I'll assume table 'user' is already created and has rows 'Host', 'User', and 'Password', otherwise this will not work...

"INSERT INTO `user` (`Host`, `User`, `Password`) VALUES ('localhost', '$UserName', '$UserPass')";
Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #2 on: January 29, 2007, 07:22:55 PM »

I just noticed you are trying to use the 'mysql' db...

The only way thats going to work is via user root and password rootwdp.

You can also do the same under phpMyAdmin and have it generate the proper sql or php code for you -- at least to get an example.
Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
yfastud
Customer, Basic Support
Jr. Member
*****
Posts: 36


View Profile
« Reply #3 on: January 29, 2007, 07:44:17 PM »

Yes, $AdminName and $AdminPass are root and yes, I'm trying to access mysql db to create new db account. Is there any restriction when accessing mysql db? I did tried w/ phpmyadmin, and it generated "create user..." instead "insert..." and I'm not sure how to run query w/ syntax "create..."

Thanks for quick reply
« Last Edit: January 29, 2007, 07:48:41 PM by yfastud » Logged
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #4 on: January 29, 2007, 07:54:53 PM »

You can run the 'create user' query just like any other query. Just use whatever syntax phpmyadmin created.
« Last Edit: January 29, 2007, 07:56:54 PM by admin » Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
yfastud
Customer, Basic Support
Jr. Member
*****
Posts: 36


View Profile
« Reply #5 on: January 29, 2007, 07:57:07 PM »

Thanks, I will try it.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!