Connecting Tech Pros Worldwide Forums | Help | Site Map

php folder create

Newbie
 
Join Date: Feb 2009
Posts: 5
#1: Feb 1 '09
hi

i have created a script that creates a user in a mysql db and i need it to create a folder for that user. the snipit of code that should do this i think is this

mkdir("/var/www/hosts/$full_name");

it is suposed to create a folder called the full name of a user entered into a form
can anyone please tell me what i am doing wrong
p.s i have made sure the perms are correct

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Feb 1 '09

re: php folder create


Turn on debugging messages.

Also, post the code you use. It may be a problem elsewhere.
Newbie
 
Join Date: Feb 2009
Posts: 5
#3: Feb 1 '09

re: php folder create


sorry im relly new to php
heres the fulll code
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3.  
  4.  
  5. include ('dbc.php'); 
  6.  
  7.  
  8. if ($_POST['Submit'] == 'Register')
  9. {
  10.    if (strlen($_POST['email']) < 5)
  11.    {
  12.     die ("Incorrect email. Please enter valid email address..");
  13.     }
  14.    if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
  15.     { 
  16.     //die ("Password does not match");
  17.     die("ERROR: Password does not match or empty..");
  18.  
  19.     }
  20.     if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
  21.     { 
  22.              die("Invalid code entered. Please enter the correct code as shown in the Image");
  23.           } 
  24.     $rs_duplicates = mysql_query("select id from users where full_name='$_POST[full_name]'");
  25.     $duplicates = mysql_num_rows($rs_duplicates);
  26.  
  27.     if ($duplicates > 0)
  28.     {    
  29.     //die ("ERROR: Account already exists.");
  30.     header("Location: register.php?msg=ERROR: Account already exists..");
  31.     exit();
  32.     }
  33.  
  34.  
  35.     $md5pass = md5($_POST['pass2']);
  36.     $activ_code = rand(1000,9999);
  37.     $server = $_SERVER['HTTP_HOST'];
  38.     $host = ereg_replace('www.','',$server);
  39.     mkdir("/var/www/hosts/.$full_name.");
  40.     mysql_query("INSERT INTO users
  41.                   (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`)
  42.                   VALUES
  43.                   ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error());
  44.  
  45.     $message = 
  46. "Thank you for registering an account with $server. Here are your login details...\n\n
  47. Your domain: $_POST[full_name] \n
  48. Password: As posted
  49. Activation Code: $activ_code \n
  50. ____________________________________________
  51. *** ACTIVATION LINK ***** \n
  52. Activation Link: http://$server/activate.php?usr=$_POST[email]&code=$activ_code \n\n
  53. _____________________________________________
  54. Thank you. This is an automated response. PLEASE DO NOT REPLY.
  55. ";
  56.  
  57.     mail($_POST['email'] , "Login Activation", $message,
  58.     "From: \"Auto-Response\" <notifications@$host>\r\n" .
  59.      "X-Mailer: PHP/" . phpversion());
  60.     unset($_SESSION['ckey']);
  61.     echo("Registration was Successful! An activation code has been sent to your email address with an activation link...");    
  62.  
  63.     exit;
  64.     }    
  65.  
  66. ?>
  67.  
here is the error msg i get
Quote:
Notice: Undefined variable: full_name in /var/www/hosts/www.easehosting.co.uk/docs/register.php on line 39

Warning: mkdir() [function.mkdir]: File exists in /var/www/hosts/www.easehosting.co.uk/docs/register.php on line 39
thank you
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#4: Feb 1 '09

re: php folder create


Hi.

Apparently, the $full_name variable is undefined, meaning that it doesn't exist before you try to use it.

If the value for this is coming from a HTML form, then you would most likely have to fetch it from the $_POST array before you use it. (Like your code does with all the other form values).

I would also advice you to validate the input before using it.
Currently you are simply passing the user input into your code without even checking to see if the values exist.
You should make sure the values exists, and that they are what you expect them to be, or your web will be vulnerable to all sorts of security threats. Like SQL Injection.
Newbie
 
Join Date: Feb 2009
Posts: 5
#5: Feb 2 '09

re: php folder create


thank you that was a big help
Reply