PHP/MYSQL being problematic?

Shane

New member
Hi everyone, I am doing a little project and am in a bit of trouble. I have figured the rest out but there is this little bit of querying giving me the sh*ts. I have multiple queries in my PHP and they all work fine, so it must be something to do with the query. However, when I go into phpMyAdmin and use SQL, it works fine???

mysql_query("#CREATING USER `".$usr."`
CREATE USER `".$usr."`@`".$hst."`;
GRANT ALL PRIVILEGES ON `".$db."` . * TO '".$usr."'@'".$hst."' WITH GRANT OPTION ;
SET PASSWORD FOR `".$usr."`@`".$hst."` = PASSWORD( '".$pwd."' );
") or die(mysql_error());

That is part of my SQL. Basically, a database and tables are made before hand. The user inputs the root details then continues to create a new account.
When creating the new account they are asked for a new account name, a password for the account, a name for a database and what the user should have access to (the new database, localhost or %).
So the database is created first, no problems there, then the user is created with the above query and I get the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GRANT ALL PRIVILEGES ON `database` . * TO 'user'@'localhost' WITH GRANT OPTION ;' at line 3

Also, the thing that I find weird, I can understand it, but I find it weird, when there is a PHP error, it gives you the line. With the MySQL error, it gives you the line of MySQL coding that has errored, here as three, when it is in fact on line 117?
Anyway, thats it.

Thanks everyone,
Shane Thompson
Thanks, I have tried that, but I shall try it again.
 
Back
Top