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:
table images: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 user_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`))
then the regmee2 stored procedure which will make the registration insert in the three previous tablesCode:CREATE TABLE `forum`.`user_images` ( `image_id` int(10) unsigned DEFAULT NULL, `userid` int(10) unsigned DEFAULT NULL)
then the register.php html coded page: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 ;
the reg.php page which makes the registration process: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"> </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>
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' ";
?>
+rock![]()
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
im having trouble putting the 'regmee2' into mysql please help!
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
Let me try this Man...
I Love That...
im having trouble putting the 'regmee2' into mysql please help!
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.
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).
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.
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks