SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mkdir problems

    ok i have a login script that allows you to create a new account if you don't have one. what i want it to do is once it registers your name, create a directory the same as your username. this is what i have:
    Code:
    <?php 
    
    include("config.php"); 
    
    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    
    // check if the username is taken
    $check = "select id from $table where username = '".$_POST['username']."';"; 
    $qry = mysql_query($check)
    or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry); 
    if ($num_rows != 0) { 
    echo "Sorry, there the username $username is already taken.<br>";
    echo "<a href=register.html>Try again</a>";
    exit; 
    } else {
    
    $path = '/dev/' + $username;
    mkdir($path);
    
    // insert the data
    $insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."')")
    or die("Could not insert data because ".mysql_error());
    
    // print a success message
    echo "Your user account has been created!<br>"; 
    echo "Now you can <a href=login.html>log in</a>"; 
    }
    
    ?>
    it registers the name correctly but when it creates the dir its named 0 instead of the username. lil help please. thanks in advance

  2. #2
    SitePoint Enthusiast thebasti's Avatar
    Join Date
    Aug 2004
    Location
    Novi Sad, Serbia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Are you sure that you actually have something in $username? Try printing its value to see if it actually contain value you expect.

    I presume that this probably has something to do with the fact that register globals is off. In most places, including both your SQL queries, you use $_POST["username"] and it a proper way to access a variable in POST. But for mkdir() you use $username. If the register globals is off, then you won't have anything in $username.

    Let me know if this helps.

    Regards,
    Basti
    "Strategy without tactics is the slowest route to victory.
    Tactics without strategy is the noise before defeat."
    - Sun Tzu
    Icebergist - a web dev blog | Orange Iceberg Web App Development


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •