Jump to content

[SOLVED] Not Creating User


papillonstudios

Recommended Posts

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();
					}
				}
		}
	}
	}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.