Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 7th September 2008, 16:50
Colum Colum is offline
Junior Member
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default This works in phpmyadmin but not in php

I have a script that adds a user to mysql and makes them a database. This is the php code:
PHP Code:
                $user mysql_escape_string($_POST['user']);
                
$pass mysql_escape_string($_POST['user']);
                
//add the shit
                
$sql 'CREATE USER \'free_'.$user.'\'@\'localhost\' IDENTIFIED BY \''.$pass.'\';'
                    
' GRANT USAGE ON *.* TO \'free_'.$user.'\'@\'localhost\' IDENTIFIED BY \''.$pass.'\' ;'
                    
' CREATE DATABASE IF NOT EXISTS `free_'.$user.'`;'
                    
' GRANT ALL PRIVILEGES ON `free_'.$user.'`.* TO \'free_'.$user.'\'@\'localhost\';'
                
mysql_query($sql) or die("<pre>".mysql_error()."<br />".$sql); 
and when I run the code, I get this error:
Code:
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 ';# MySQL returned an empty result set (i.e. zero rows). GRANT USAGE ON *.* TO 'f' at line 1
CREATE USER 'free_testing'@'localhost' IDENTIFIED BY 'testing';
GRANT USAGE ON *.* TO 'free_testing'@'localhost' IDENTIFIED BY 'testing' ;CREATE DATABASE IF NOT EXISTS `free_testing`;
GRANT ALL PRIVILEGES ON `free_testing`.* TO 'free_testing'@'localhost';
now if I take the sql code from above, which is this:
Code:
CREATE USER 'free_testing'@'localhost' IDENTIFIED BY 'testing';
GRANT USAGE ON *.* TO 'free_testing'@'localhost' IDENTIFIED BY 'testing' ;CREATE DATABASE IF NOT EXISTS `free_testing`;
GRANT ALL PRIVILEGES ON `free_testing`.* TO 'free_testing'@'localhost';
and run it in phpmyadmin it works. This is all on the same server. Whats up?
Reply With Quote
Sponsored Links
  #2  
Old 8th September 2008, 12:48
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,751 Times in 2,581 Posts
 
Default

I'd use double quotes for SQL statements:

Code:
$sql = "CREATE USER 'free_".$user."'@'localhost' IDENTIFIED BY '".$pass."';"
       . " GRANT USAGE ON *.* TO 'free_".$user."'@'localhost' IDENTIFIED BY '".$pass."' ;"
       . " CREATE DATABASE IF NOT EXISTS `free_".$user."`;"
       . " GRANT ALL PRIVILEGES ON `free_".$user."`.* TO 'free_".$user."'@'localhost';";
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 18:26
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 10:29
ispconfig php 5 errors itamarjp Installation/Configuration 8 25th April 2008 11:20
network issues now it says "401 The web site is blocked by administrator" Check General 3 26th February 2008 15:22
Apache2 Freezes celtic Server Operation 31 28th May 2007 18:18


All times are GMT +2. The time now is 02:04.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.