renfley Posted July 17, 2011 Share Posted July 17, 2011 irst question is i guess i cant get the mkdir to create a members/001 and i cant figure it out for the life of me any help would be freaking awsome <?PHP //Database Information $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "xxx"; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $fname = $_POST['fname']; $lname = $_POST['lname']; $city = $_POST['city']; $username = $_POST['username']; $password = md5($_POST['password']); $email = $_POST['email']; $newsletter = $_POST['newsletter']; $pubdir = $_POST['pubdir']; // lets check to see if the username already exists $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } // lf no errors present with the username // use a query to insert the data into the database. $query = "INSERT INTO users (fname, lname, city, username, password, email, newsletter, pubdir) VALUES('$fname', '$lname', '$city', '$username', '$password', '$email', '$newsletter', '$pubdir')"; mysql_query($query) or die(mysql_error()); mysql_close(); //this will create a folder for the customer. //$query1= "Select UID Where username = $username " //$id = //$id = mysql_insert_id(); // this will get the id that you inserted to your table. //mkdir("members/$id", 0755); $id = mysql_query("SELECT id FROM users WHERE username='$username'"); // this will get the id that you inserted to your table. mkdir("$id"); echo "You have successfully Registered"; // mail user their information $yoursite = "www.xxx.com"; $webmaster = "Administrator"; $youremail = "info@xxx.com"; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $fname, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "Your information has been mailed to your email address."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/ Share on other sites More sharing options...
wildteen88 Posted July 17, 2011 Share Posted July 17, 2011 First create the members folder and then give it write permissions (0755 or 0777). Then in your PHP script you'd use mkdir('members/001'); to create the 001 folder within the members folder. Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243710 Share on other sites More sharing options...
renfley Posted July 17, 2011 Author Share Posted July 17, 2011 thats would work bu i wanna pass a $var in the mkdir to create a folder based on the id of the user? if that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243713 Share on other sites More sharing options...
wildteen88 Posted July 17, 2011 Share Posted July 17, 2011 Then replace 001 with your actual variable and replace the single quotes with double quotes mkdir("members/$yourr_var"); Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243714 Share on other sites More sharing options...
renfley Posted July 17, 2011 Author Share Posted July 17, 2011 Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\renfley\config\register.php on line 47 You have successfully Registered The members dir is already created i only need to create a folder based on my variable, $id = mysql_query("SELECT id FROM users WHERE username='$username'"); // this will get the id that you inserted to your table. mkdir("members/$id"); echo "You have successfully Registered"; Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243717 Share on other sites More sharing options...
wildteen88 Posted July 17, 2011 Share Posted July 17, 2011 try mkdir("members/$yourr_var", 0755, true); Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243718 Share on other sites More sharing options...
renfley Posted July 17, 2011 Author Share Posted July 17, 2011 Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\renfley\config\register.php on line 47 You have successfully Registered Still getting error Safe mode is off ive already ruled that one out but this one is very strange my query is fine i just think there some issue with passing a $ in the mkdir? Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243719 Share on other sites More sharing options...
wildteen88 Posted July 17, 2011 Share Posted July 17, 2011 mkdir is failing because the folder(s) already exists. Change mkdir("members/$id", 0755, true); to if(!is_dir("members/$id")) { mkdir("members/$id", 0755, true); } else { echo "the folder members/$id already exits!"; } Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243723 Share on other sites More sharing options...
srikanth03565 Posted July 17, 2011 Share Posted July 17, 2011 Hi Before running your script please check the permissions of folder "members" members FOLDER has write permissions for your webserver like apache. so provide write permissions i.e 777 to members and try it will works fine. Quote Link to comment https://forums.phpfreaks.com/topic/242185-registration-php-and-mkdir/#findComment-1243727 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.