+ Reply to Thread
Results 1 to 10 of 10

Thread: register/upload photo /have a new page for each user after registration

  1. #1
    omar_a_k's Avatar
    omar_a_k is offline Newbie
    Join Date
    Jan 2009
    Location
    egypt
    Posts
    10
    Blog Entries
    1
    Rep Power
    0

    Post register/upload photo /have a new page for each user after registration

    hi every one ,in this tutorial i will illustrate how to make a registration process that include a firstly : DB with three tables: users/images/user images
    and stored procedure called regmee2 for inserting records in the three tables
    secondly : a registration form including in it javascript code for choosing whether to add photo path or photo url .thirdly the reg.php page :which do the following 1.register the use 2.make for him a directory on the sever 3.creating a php page for him containing his uploaded photo and the url of his page .
    NOTICE: the image will be stored by its path and will be retreived also by its path to decrease the load of the I/O of the db.

    lets start with the database:
    table users:
    Code:
    CREATE TABLE  `forum`.`users` (
      `user_id` int(10) NOT NULL AUTO_INCREMENT,
      `user_name` varchar(20) DEFAULT NULL,
      `password` varchar(50) DEFAULT NULL,
      `firstname` varchar(50) DEFAULT NULL,
      `lastname` varchar(50) DEFAULT NULL,
      `bad` tinyint(1) DEFAULT NULL,
      `email` varchar(255) DEFAULT NULL,
      `role_id` int(10) DEFAULT NULL,
      PRIMARY KEY (`user_id`),
      UNIQUE KEY `user_name` (`user_name`),
      UNIQUE KEY `email` (`email`))
    table images:
    Code:
    CREATE TABLE  `forum`.`images` (
      `image_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `image_path` varchar(200) DEFAULT NULL,
      `image_url` varchar(45) DEFAULT NULL,
      PRIMARY KEY (`image_id`),
      UNIQUE KEY `image_path` (`image_path`),
      UNIQUE KEY `image_url` (`image_url`))
    table user_images :
    Code:
    CREATE TABLE  `forum`.`user_images` (
      `image_id` int(10) unsigned DEFAULT NULL,
      `userid` int(10) unsigned DEFAULT NULL)
    then the regmee2 stored procedure which will make the registration insert in the three previous tables
    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE  `forum`.`regmee2`(img2 varchar(200), usrnme varchar(20), psswrd varchar(50), frstnme varchar(50),lstnme varchar(50),email varchar(255))
    BEGIN
    
    
    insert into IMAGES (image_url) values (img2);
    insert into dbo_users (user_name,password,firstname,lastname,email) values
    (usrnme,psswrd,frstnme,lstnme,email);
    insert into user_images (userid ,image_id ) select u.user_id ,i.image_id from dbo_users u ,images i where user_id=(select user_id from dbo_users where user_name=usrnme ) and image_id=(select image_id from images where image_url=img2);
    END $$
    
    DELIMITER ;
    then the register.php html coded page:
    Code:
    <html>
    <head>
    <script type="text/javascript" src="choose.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body><form action="reg.php" target="reg.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <table width="567" border="0">
      <tr>
        <td width="124">firstname</td>
        <td width="229"><label>
          <input type="text" name="first" id="first" />
        </label></td>
        <td width="200" rowspan="5">&nbsp;</td>
      </tr>
      <tr>
        <td>lastname</td>
        <td><label>
          <input type="text" name="last" id="last" />
        </label></td>
        </tr>
      <tr>
        <td>username</td>
        <td><label>
          <input type="text" name="userreg" id="userreg" />
        </label></td>
        </tr>
      <tr>
        <td height="32">password</td>
        <td><label>
          <input type="text" name="passreg" id="passreg" />
        </label></td>
        </tr>
      <tr>
        <td>email</td>
        <td><label>
          <input type="text" name="email" id="email" />
        </label></td>
        </tr>
      <tr>
        <td>image_path</td>
        <td><input type="file" name="photopath" id="pc"   /></td>
        <td><label>
          <input name="radio1" type="radio"  onfocus="disableweb()"value="1" checked="checked" />from my pc
        
        </label></td>
      </tr>
      <tr>
        <td>image_url</td>
        <td><input type="text" name="photopath" id="web" disabled="disabled" /></td>
        <td><input name="radio1" type="radio" value="2" onclick="disablepc()"  />
    from the web </td>
      </tr>
      <tr>
        <td><label>
          <input type="submit" name="submit" id="submit" value="submit" />
        </label></td>
        <td><label>
          <input type="reset" name="reset" id="reset" value="reset" />
    
    
    
        </label></td>
        <td><label></label></td>
      </tr>
    </table>
    
    </form>
    </body>
    </html>
    the reg.php page which makes the registration process:
    Code:
    <?php
    $first 
    =$_POST['first'];
    $last $_POST['last'];
    $username $_POST['userreg'];
    $pass $_POST['passreg'];
    $email $_POST['email'];
    $file $_FILES['photopath']['name'];
    //make directory for the user by his username
    mkdir($username,0777);
    //the temp folder
    $temp $_FILES['photopath']['tmp_name'];
    $conn=mysql_connect("localhost","root",null,null);
    mysql_selectdb("forum",$conn);
    //here we  wil call the regmee2 stroed procedure which will make the insert to three tables users ,images  ,user_images 
    //it will store the path of the uploaded image in the server no the image it self 
    $sql ="call regmee2('$username/$file','$username','$pass','$first','$last','$email')";
    $result =mysql_query($sql,$conn) or die (mysql_error());
    //move the posted image from the temp to the server
    move_uploaded_file($temp"$username/$file"); 

    $pic='$username/$file';
    //making a new php file page having his phot and a welcome messgae and the path of his page 
    touch("$username/$username.php");
    $fp fopen("$username/$username.php"'w');
    $php "html><body>
    welcome:$username <br />
    what a great photo
    <img src='$file' width=200 height=200 />
     your page url is  'http'://localhost/forum 2nd try/$username/$username.php' </body>"  
    ;
    fwrite($fp,$php);
    //redirecting him to his new page :
    echo "<META HTTP-EQUIV='refresh' content='0; url=$username/$username.php' ";



    ?>

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2008
    Location
    Istog, Kosova
    Posts
    4,001
    Blog Entries
    1
    Rep Power
    40

    Re: register/upload photo /have a new page for each user after registration

    +rock
    Interested in participating in community events?
    Want to harness your programming skill and turn it into absolute prowess?
    Come join our programming events!

  4. #3
    Join Date
    Aug 2009
    Location
    England
    Posts
    23
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    im having trouble putting the 'regmee2' into mysql please help!

  5. #4
    madhaninfo is offline Newbie
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    im having trouble putting the 'regmee2' into mysql please help! anyone please help to solve this i am doing project based on this
    Last edited by madhaninfo; 09-16-2009 at 10:36 PM. Reason: to use it in my project

  6. #5
    Cruz3N is offline Newbie
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    Let me try this Man...
    I Love That...

  7. #6
    madhaninfo is offline Newbie
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    im having trouble putting the 'regmee2' into mysql please help!

  8. #7
    cesarchile is offline Newbie
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    hi, i don`t understand the file 'regmee2, mysql return an error, and the the "dbo_users" why dbo?, thanks in advance

  9. #8
    bravemarshal is offline Newbie
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    Quote Originally Posted by cesarchile View Post
    hi, i don`t understand the file 'regmee2, mysql return an error, and the the "dbo_users" why dbo?, thanks in advance
    Me too. When i try to execute it in phpmysql, that is the regmee2 file:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `forum`.`regmee2`(img2 varchar(200), usrnme varchar(20), psswrd varchar(50), frstnme varchar(50),lstnme varchar(50),email varchar(255))
    BEGIN


    insert into IMAGES (image_url) values (img2);
    insert into dbo_users (user_name,password,firstname,lastname,email) values
    (usrnme,psswrd,frstnme,lstnme,email);
    insert into user_images (userid ,image_id ) select u.user_id ,i.image_id from dbo_users u ,images i where user_id=(select user_id from dbo_users where user_name=usrnme ) and image_id=(select image_id from images where image_url=img2);
    END $$

    DELIMITER ;

    I get the error message: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5.
    Please can you tell me what do do. Perhaps i need the right version for my server.

  10. #9
    bbqroast's Avatar
    bbqroast is offline Programming God
    Join Date
    Jul 2010
    Posts
    506
    Blog Entries
    9
    Rep Power
    9

    Re: register/upload photo /have a new page for each user after registration

    Nice to see someone utilizing the far more effective method of putting the images in a folder with a url in the MySQL table.

    Have you not considered simply using the GET method to show the pages? So the users page would be:
    localhost/users/username.php?id=(user's id)
    Then the page would be easy to change? You can also use htaccess to make it nicer (eg localhost/users/bbqroast instead of localhost/users/username.php?id=2).
    Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

  11. #10
    bravemarshal is offline Newbie
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Re: register/upload photo /have a new page for each user after registration

    bbqroast, You didn't give a direct solution to the problem. What you suggested is nice though but it is a task to venture into later. I need to know where my table has error because without it worj=king i cannot get through the job at hand. please be kind to help look at the regmee2 table code and tell me what is wrong with it or at least give me a working code for the same task. I have been trying several ideas that have not worked yet. If you have another complete program that can achieve the above session registration and display of registered information on a page along with user photo image, please share it with us.
    Thanks for your response though. It's hard to get response in so short a time. i have visited daily duting my studies for something new and hardly see new post. Please stay with me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Intermediate PHP Register Page
    By Epatron in forum PHP Tutorials
    Replies: 3
    Last Post: 08-16-2011, 11:39 AM
  2. Link my user registration/login to my blog?
    By wheay in forum Database & Database Programming
    Replies: 2
    Last Post: 04-26-2011, 10:25 AM
  3. User Registration...
    By isuru in forum PHP Development
    Replies: 1
    Last Post: 04-02-2011, 07:20 PM
  4. User avatar + upload [HELP]
    By frozie in forum PHP Development
    Replies: 5
    Last Post: 06-17-2010, 01:28 AM

Tags for this Thread

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