Hello,
I have create a registration form in the Following path
Path : C:\Program Files (x86)\EasyPHP 2.0b1\www\Conne ctivity
In the folder "Connectivi ty", my php file "Registration.p hp" is created. And there is One another folder "Upload" in this folder.
Here I have create 3 file
Connectivity.ph p - For establish connection to database
Insert.php - For Insert Qurey
Registration.ph p
Here is my code of Registration.ph p
When I have submit the form, the data are inserted successfully, but the photo doesn't move in "Upload" folder.
Here, Line 168 to 184 is code for File Upload.
What changes I have to do in my code for save the image/photo in "Upload" folder?????
Please help me to solve this problem
If need to view other 2 files, here is the code
Code of Insert.php
Code of Connectivity.ph p
I have create a registration form in the Following path
Path : C:\Program Files (x86)\EasyPHP 2.0b1\www\Conne ctivity
In the folder "Connectivi ty", my php file "Registration.p hp" is created. And there is One another folder "Upload" in this folder.
Here I have create 3 file
Connectivity.ph p - For establish connection to database
Insert.php - For Insert Qurey
Registration.ph p
Here is my code of Registration.ph p
Code:
<html>
<head>
<script type="text/javascript" language="javascript">
function validate(frm)
{
with(frm)
{
if(username.value=="")
{
alert("Please Enter Username!");
username.focus();
return false;
}
if(password.value=="")
{
alert("Please Enter Password!");
password.focus();
return false;
}
if(address.value=="")
{
alert("Please Enter Address!");
address.focus();
return false;
}
if(course.value=="" || course.value=="0")
{
alert("Please Select Course!");
course.focus();
return false;
}
if(hobby.value=="" || hobby.value=="0")
{
alert("Please Select Hobby!");
hobby.focus();
return false;
}
if(photo.value=="")
{
alert("Please Select Profile Picture!");
photo.focus();
return false;
}
if(gender.value=="")
{
alert("Please Select Gender!");
gender.focus();
return false;
}
if(!php.checked && !rdbms.checked && !java.checked && !asp.checked && !dcn.checked)
{
alert("Please Select Skill!");
php.focus();
return false;
}
return true;
}
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data" name="frmRegistration">
<table>
<tr>
<td>Enter the Username :-</td>
<td>
<input type="textbox" id="txtUN" name="username">
</td>
<tr>
<tr>
<td>Enter the Password :-</td>
<td>
<input type="password" id="txtPassword" name="password">
</td>
</tr>
<tr>
<td>Enter the Address :-</td>
<td>
<textarea id="txtPassword" name="address" rows="5" columns="10"></textarea>
</td>
</tr>
<tr>
<td>Course :-</td>
<td>
<select name="course" id="course">
<option value="0">Select Course</option>
<option value="B.Sc.IT">B.Sc.IT</option>
<option value="BCA">BCA</option>
<option value="B.Com">B.Com</option>
<option value="BBA">BBA</option>
<option value="M.Sc.IT">M.Sc.IT</option>
<option value="MCA">MCA</option>
<option value="M.Com">M.Com</option>
<option value="MBA">MBA</option>
</select>
</td>
</tr>
<tr>
<td>Hobby :-</td>
<td>
<select name="hobby" id="hobby" multiple="multiple">
<option value="0" selected>Please Select</option>
<option value="Reading">Reading</option>
<option value="Writing">Writing</option>
<option value="Collecting Different Things">Collecting Different Things</option>
<option value="Travelling">Travelling</option>
<option value="Walking">Walking</option>
<option value="Playing">Playing</option>
<option value="Cooking">Cooking</option>
<option value="Music">Music</option>
<option value="Other">Other</option>
</select>
</td>
</tr>
<tr>
<td>Profile Picture :-</td>
<td>
<input type="file" name="photo"/>
</td>
</tr>
<tr>
<td>Gender :-</td>
<td>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</td>
</tr>
<tr>
<td>Skills :-</td>
<td>
<input type="checkbox" name="php" value="PHP">PHP
<input type="checkbox" name="rdbms" value="RDBMS">RDBMS
<input type="checkbox" name="java" value="Java">Java
<input type="checkbox" name="asp" value="ASP.NET">ASP.NET
<input type="checkbox" name="dcn" value="DCN">DCN
</td>
</tr>
<tr>
<td colspan="2">
<br>
<input type="submit" name="submit" value="Submit" onclick="javascript:return validate(document.frmRegistration);">
<input type="reset" name="clear" value="Reset">
<br><br>
<input type="submit" name="view" value=" View Records ">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST["submit"]))
{
if($_FILES["photo"]["name"]!=" ")
{
/*echo "<pre>";
print_r($_FILES);
echo "</pre>";*/
$target="Upload/";
echo $target.$_FILES["photo"]["name"];die;
if(!file_exists($target.$_FILES["photo"]["name"]))
{
move_uploaded_file($_FILES["photo"]["tmp_name"],$target.$_FILES["photo"]["name"]);
$photo=$_FILES["photo"]["name"];
}
else
{
echo "Already exists!<br>";
}
}
include("Insert.php");
}
?>
</body>
</html>
Here, Line 168 to 184 is code for File Upload.
What changes I have to do in my code for save the image/photo in "Upload" folder?????
Please help me to solve this problem
If need to view other 2 files, here is the code
Code of Insert.php
Code:
<?php
include("Connectivity.php");
if(isset($_POST["submit"]))
{
extract($_POST);
$php=isset($_POST["php"])?$_POST["php"]:"";
$rdbms=isset($_POST["rdbms"])?$_POST["rdbms"]:"";
$java=isset($_POST["java"])?$_POST["java"]:"";
$asp=isset($_POST["asp"])?$_POST["asp"]:"";
$dcn=isset($_POST["dcn"])?$_POST["dcn"]:"";
$Password=md5($password);
$sql="insert into registration(
Username,Password,Address,
Course,Hobby,ProfilePic,Gender,
PHP,RDBMS,JAVA,ASP,DCN
)
values(
' ".$username." ',' ".$Password." ',' ".$address." ',' ".
$course." ',' ".$hobby." ',' ".$photo." ',' ".$gender." ',' ".
$php." ',' " .$rdbms." ',' ".$java." ',' ".$asp." ',' ".$dcn." ')";
//echo $sql;die;
mysql_query($sql);
echo "Successfully Inserted";
}
?>
Code of Connectivity.ph p
Code:
<?php
$host="localhost";
$username="root";
$password="";
$link=mysql_connect($host,$username,$password);
if($link)
{
mysql_select_db("student",$link);
}
else
{
echo "Error!";
die;
}
?>
Comment