Nxt Posted September 24, 2008 Share Posted September 24, 2008 Hey! Okay, so i've been looking up some tutorials on PHP and MySQL. I feel that downloading a pre-made script limits on your creativity and handling procedures. Plus, you get that damn copyright info that will indicate to other users on your site that you never made that sciprt. So, I write up a test script to 1) Connect to Mysql server. 2) Create a database. 3) Insert a new table inside the database. Here's the code: <?php $sql = mysql_connect('localhost','nxtwaren_God',"mypassword") or die("Couldn't connect to mysql server.".mysql.error()); ?> That's in the sqlconnect.php now here's the createdb.php : ?php include 'sqlconnect.php'; // create database mysql_query("CREATE DATABASE nxtwaren_blogsystem") or die(mysql_error()); // Select Database mysql_select_db("nxtwaren_blogsystems",$sql) or die(mysql_error()); // Create a new table! mysql_query("CREATE TABLE users ( username varchar(30), age tinyint(2), posts mediumint(9) ) ") or die(mysql_error()); echo("Database was created successfully!"); // Lets say we got the information via a POST form $username = 'Bob'; $age = 40; $posts = 5000; mysql_query("INSERT INTO users (username, age, posts) VALUES ('".$username."', ".$age.", ".$posts."") or die(mysql_error()); echo ("Successfully inserted data into new table!"); ?> So the result when I run the script createdb.php is: Access denied for user 'nxtwaren_God'@'localhost' to database 'nxtwaren_blogsystems' Any help-would be really appreciated! Thanks! -NxT Quote Link to comment Share on other sites More sharing options...
waynew Posted September 25, 2008 Share Posted September 25, 2008 You don't have the correct permissions. Quote Link to comment Share on other sites More sharing options...
Stefan Posted September 26, 2008 Share Posted September 26, 2008 There could be several reasons for this! :-\ If I get error messages that I can`t pinpoint, I Google the error message to see if I didn`t miss anything and to better determine what I did wrong! make sure the database settings in config.php are correct or GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password'; FLUSH PRIVILEGES; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.