Hi, today i am going to tell you about how to work on simple user signup form with image upload using php and mysql, it is very easy to write the code those who are start up in php and mysql it is a basic signup form with out any javascript or jquery validation integrated. i just write the basic code for you people. lets see how to write the code
inside the condtion write the mysql_query() function and use INSERT INTO command to send the form data to database table here users is the database table and maintane the table name order to form order while you giving
for file or image upload use $_FILES[] command to get the file name and we can give many conditions like type, size and form validation but in this lesson i am just giving a basic script without any restictions to image or file, to store the uploaded image use move_uploaded_file() function to move the uploaded file to particular location
Live Demo
Download Script
PHP
in php index.php file just take the basic form with few input fields with file field and arrange it as you like in the order, now give the names to all input fields, before taking a form fields you must insert a form and inside the form you take the all input fields and make sure the from tag should be have enctype="multipart/form-data" the attribute is use to transfer the file, and assign the register.php file to action attribute<form action="register.php" method="post" enctype="multipart/form-data" name="form1"> <div id="formbox"> <ul> <li> <span>First Name:</span><br/> <input name="fname" type="text" id="fname" class="forms11"> </li> <li>Last Name<span>:</span><br/> <input name="lname" type="text" id="lname" class="forms11"> </li> <li> <span>Email:</span><br/> <input name="email" type="text" id="email" class="forms11"> </li> <li>Password<span>:</span><br/> <input name="pass" type="password" id="pass" class="forms11"> </li> <li>Gender<span>:</span><br/> <select name="gender" class="forms11" id="gender"> <option selected value="">Select</option> <option value="male">Male</option> <option value="female">Female</option> </select> </li> <li style="margin-top:5px;"> <input name="img" type="file"> </li> <li style="margin-top:5px;"> <input name="send" type="submit" value="Signup" class="send1"> </li> </ul> </div> </form>
register.php
in this file include the db,php file using include() function and extract($REQUEST) function is use to extracting the requesting form data, use the if condition because the script will run when we click the send buttoninside the condtion write the mysql_query() function and use INSERT INTO command to send the form data to database table here users is the database table and maintane the table name order to form order while you giving
for file or image upload use $_FILES[] command to get the file name and we can give many conditions like type, size and form validation but in this lesson i am just giving a basic script without any restictions to image or file, to store the uploaded image use move_uploaded_file() function to move the uploaded file to particular location
<?php extract($_REQUEST); include("db.php"); if($send){ $image=$_FILES['img']['name']; move_uploaded_file($_FILES['img']['tmp_name'],'userimages/'.$image); mysql_query("insert into users(fname,lname,email,pass,gender,image) values('$fname','$lname','$email','$pass','$gender','$image')"); } ?>
No comments :
Post a comment