papillonstudios Posted August 2, 2009 Share Posted August 2, 2009 When i submit the following form i get this error Could not Select DB: Access denied for user ''@'localhost' to database 'db_name' heres my code: <?php include ('defs.php'); if (!defined('error_check')) die('You Cannot Access This Page From This Location'); //If the form hasn't been submitted, show it. if (!isset($_POST['post'])) { ?> <h3>Step 3 - Create Admin User</h3> <form action action="index.php?step=step3" method="post"> <input type="hidden" value="1" name="post" /> <table width="75%"> <tr><td>Username </td><td><input type="text" class="input" name="username" /></td></tr> <tr><td>Password </td><td><input type="password" class="input" name="password" /></td><td><input type="password" class="input" name="cpassword" /></td></tr> <tr><td>Email </td><td><input type="text" class="input" name="email" /></td></tr> <tr><td><input type="submit" class="input" name="submit" value="Create Account" /></td></tr> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forms secure it all. $username = secure($_POST['username']); $password = secure($_POST['password']); $cpassword = secure($_POST['cpassword']); $email = secure($_POST['email']); //Get their IP Address $ip = secure($_SERVER['REMOTE_ADDR']); //And the time they signed up $signup = time(); //If anything is empty... if (!$username | !$password | !$cpassword | !$email) { echo '<img src="i/warning.png" alt="warning">eek! please fill all fields!!'; } else { //If the passwords dont match if ($password != $cpassword) { echo 'The passwords do not match'; } else { //If the email they entered wasn't an authentic email.. if (!isEmail($email)) { echo "You didn't enter a valid email address"; } else { //Encrypt the password $shuffler = ''.$username.''.$cpassword.''; $salt = str_shuffle($shuffler); $encpass = sha1($password . $salt); $connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!connect) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db(DB_NAME); if (!$selectdb) { die('Could not Select DB: ' . mysql_error()); } $admin = "INSERT INTO `users` (username, password, email, ip, signup, membergroup) VALUES ('$username', '$encpass', '$email', '$ip', '$signup', 'admin')"; $aemail = "INSERT INTO `info` (aemail) VALUES ('$email')"; mysql_query($admin) or die ('Couldn\'t insert Data' . mysql_error()); mysql_query($aemail) or die ('Couldn\'t insert Data' . mysql_error()); //If the insert went ok... if (mysql_query('$admin, $aemail')) { //Tell them their user info echo 'Success, you are now registered<br />'; echo 'You can now login using the following information<br /><br />'; echo "Username: <strong>$username</strong><br />"; echo "Password: <strong>$password</strong><br />"; echo "Login <a href='index.php?action=login'>Go</a>"; } else { echo 'Error, user not added' . mysql_error(); } } } } } ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 2, 2009 Share Posted August 2, 2009 Seems like you got a pretty descriptive error. The user specified does not have access to the database specified. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted August 2, 2009 Author Share Posted August 2, 2009 Found the problem. I get DB_NAME, DB_HOST etc. from a file called defs.php So now my question is how do i add a line to a file and not over write everything in the file so i have the database connection settings in defs.php and i want to add the salt to that file Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 2, 2009 Share Posted August 2, 2009 defs.php is just code. Those are php constants that get set using php define(); I don't know what you mean by "add salt to that file" but in terms of code, you can edit any php file using a simple text editor. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted August 2, 2009 Author Share Posted August 2, 2009 ok, to get this straight the line needs to be added dynamically when the admin creates his account. i found, i code out this in my fopen function 'a+' but i need it to go inside the <?php and ?> tags not at the very end heres defs.php <?php DEFINE ('SALT', 'a4id9596n8m85'); ?> so instead of the salt i would have all the database connection settings and i want to add the salt line Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted August 2, 2009 Author Share Posted August 2, 2009 i figured out a quick solution Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 2, 2009 Share Posted August 2, 2009 With PHP there is no need to include the end tag, and there are even advantages to not including it. With that said you might want to make sure that the file didn't already have that definition in it. So one way to handle it is to read the file in first, and if you determine you need to modify it, then open it for rewrite and write out the entire contents, along with changes. 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.