Multi image
Login.php
<!DOCTYPE html>
<html>
<head>
<title>abc</title>
</head>
<body>
<form method="post" action="loginaction.php">
enter email:<input type="email" name="email"><br>
enter password:<input type="password" name="password"><br>
<input type="submit" name="submit" value="submit"><br>
<a href="forminsert.php">New registration</a>
</form>
</body>
</html>
connection.php
<?php
$servername="localhost";
$username="root";
$password="";
$db="mwf9to12";
$conn=mysqli_connect($servername,$username,$password,$db);
//print_r($conn);
?>
loginaction.php
<?php
session_start();
include("connection.php");
$email=$_REQUEST["email"];
$pass=md5($_REQUEST["password"]);
//echo $email,$pass;
$sql="SELECT * FROM mpa_mulimg WHERE email='$email' AND password='$pass'";
$data=mysqli_query($conn,$sql);
$totalresponse=mysqli_num_rows($data);
$result= mysqli_fetch_assoc($data);
if($totalresponse)
{
if($result['user']=='admin'){
$_SESSION['aid']=$result['id'];
header("location:displayadmin.php");
}else{
$_SESSION['cid']=$result['id'];
header("location:displayclient.php");
}
}
else
{
echo "Login failed";
}
?>
forminsert.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>form insert</title>
</head>
<body>
<form method="post" action="forminsertaction.php" enctype="multipart/form-data">
name:<input type="text" name="name"><br><br>
email:<input type="email" name="email"><br><br>
address:<input type="text" name="address"><br><br>
phone:<input type="text" name="phone"><br><br>
password:<input type="password" name="password"><br><br>
gender:
<input type="radio" name="gender" value="male">male
<input type="radio" name="gender" value="female">female
<input type="radio" name="gender" value="others">others<br><br>
degree:<select name="degree">
<option>Select</option>
<option value="B.A">B.A</option>
<option value="B.SC">B.SC</option>
<option value="B.TECH">B.TECH</option>
<option value="M.A">M.A</option>
</select><br><br>
language:<input type="checkbox" name="language[]" value="bengali">bengali
<input type="checkbox" name="language[]" value="english">english
<input type="checkbox" name="language[]" value="hindi">hindi<br><br>
date:<input type="date" name="date"><br><br>
dob:<input type="date" name="date"><br><br>
image1:<input type="file" name="uploadimage"><br><br>
image2:<input type="file" name="uploadimage2"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
forminsertaction.php
<?php
include("connection.php");
$name=$_REQUEST["name"];
$email=$_REQUEST["email"];
$address=$_REQUEST["address"];
$phone=$_REQUEST["phone"];
$password=md5($_REQUEST["password"]);
$gender=$_REQUEST["gender"];
$degree=$_REQUEST["degree"];
//$language=$_REQUEST["language"];
$lang=implode(",",$_REQUEST["language"]);
$date=$_REQUEST["date"];
$dob=$_REQUEST["date"];
$filename=$_FILES["uploadimage"]["name"];
$tempname=$_FILES["uploadimage"]["tmp_name"];
$filename2=$_FILES["uploadimage2"]["name"];
$tempname2=$_FILES["uploadimage2"]["tmp_name"];
$folder="image/".$filename;
$folder2="image/".$filename2;
move_uploaded_file($tempname,$folder);
move_uploaded_file($tempname2,$folder2);
$fold= $folder.",".$folder2;
$sql="INSERT INTO `mpa_mulimg`(`id`, `name`, `email`, `address`, `phone`, `password`, `gender`, `degree`, `language`, `date`, `dob`,`user`,`picsource`) VALUES ('','$name','$email','$address','$phone','$password','$gender','$degree','$lang','$date','$dob','client','$fold')";
$data=mysqli_query($conn,$sql);
if($data)
{
//echo "Inserted data successfully";
// echo $gender;
header("location:login.php");
}
else
{
echo "Not inserted";
}
?>
edit.php
<?php
session_start();
include("connection.php");
$id=$_SESSION["id"]=$_REQUEST['eid'];
//$user=$_REQUEST["ep"];
//echo $user;
//ths above whole line means it will redirect to edit page and will show the user no. that is ep
$sql="SELECT * FROM mpa_mulimg WHERE id='$id'";
$data=mysqli_query($conn,$sql);
$result= mysqli_fetch_assoc($data);//it will show the array key with value
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>form edit</title>
</head>
<body>
<form method="post" action="formeditaction.php" enctype="multipart/form-data">
name:<input type="text" name="name" value="<?php echo $result['name']?>"><br>
email:<input type="email" name="email" value="<?php echo $result['email']?>"><br>
address:<input type="text" name="address" value="<?php echo $result['address']?>"><br>
phone:<input type="text" name="phone" value="<?php echo $result['phone']?>"><br>
<!--password:<input type="password" name="password"><br>-->
gender:<input type="radio" name="gender" value="male"<?php if($result['gender']=='male'){echo "checked";}?>>male<br>
<input type="radio" name="gender" value="female"<?php if($result['gender']=='female'){echo "checked";}?>>female<br>
<input type="radio" name="gender" value="others"<?php if($result['gender']=='others'){echo "checked";}?>>others<br>
degree:<select name="degree" >
<option>Select</option>
<option value="B.A" <?php if($result['degree']=='B.A'){echo "selected";}?>>B.A</option>
<option value="B.SC" <?php if($result['degree']=='B.SC'){echo "selected";}?>>B.SC</option>
<option value="B.TECH" <?php if($result['degree']=='B.TECH'){echo "selected";}?>>B.TECH</option>
<option value="M.A" <?php if($result['degree']=='M.A'){echo "selected";}?>>M.A</option>
</select><br>
language:
<?php
$langArray=explode(",",$result['language']);//$result['language'] is the attr name
?>
<input type="checkbox" name="language[]" value="bengali" <?php if(in_array("bengali",$langArray)){echo "checked";}?>>bengali
<input type="checkbox" name="language[]" value="english" <?php if(in_array("english",$langArray )){echo "checked";}?>>english
<input type="checkbox" name="language[]" value="hindi" <?php if(in_array("hindi",$langArray )){echo "checked";}?>>hindi<br>
date:<input type="date" name="date" value="<?php echo $result['date']?>"><br>
dob:<input type="date" name="dob" value="<?php echo $result['dob']?>"><br>
<?php
$arr = explode(",", $result["picsource"]);
$_SESSION['oldpic_path1']=$arr[0];
$_SESSION['oldpic_path2']=$arr[1];
?>
image1:<input type="file" name="uploadimage"><br>
<img src='<?php echo $arr[0];?>'height="100" width="200"><br>
image2:<input type="file" name="uploadimage2"><br>
<img src='<?php echo $arr[1];?>'height="100" width="200"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<!-- in array: It can check the element is present in array or not -->
formeditaction.php
<?php
session_start();
include("connection.php");
$id=$_SESSION["id"];
$name=$_REQUEST["name"];
$email=$_REQUEST["email"];
$address=$_REQUEST["address"];
$phone=$_REQUEST["phone"];
// $password=md5($_REQUEST["password"]);
$gender=$_REQUEST["gender"];
$degree=$_REQUEST["degree"];
//$language=$_REQUEST["language"];
$lang=implode(",",$_REQUEST["language"]);
$date=$_REQUEST["date"];
$dob=$_REQUEST["dob"];
$filename=$_FILES["uploadimage"]["name"];
$tempname=$_FILES["uploadimage"]["tmp_name"];
$filenames2=$_FILES["uploadimage2"]["name"];
$tempnames2=$_FILES["uploadimage2"]["tmp_name"];
$folder="image/".$filename;
$folders2="image/".$filenames2;
move_uploaded_file($tempname,$folder);
move_uploaded_file($tempnames2,$folders2);
$folder1=$_SESSION['oldpic_path1'];
$folder2=$_SESSION['oldpic_path2'];
if($folder=="image/")
{
$folder1=$folder1.",".$folder2;
$sql="UPDATE `mpa_mulimg` SET `name`='$name',`email`='$email',`address`='$address',`phone`='$phone',`gender`='$gender',`degree`='$degree',`language`='$lang',`date`='$date',`dob`='$dob',`picsource`='$folder1' WHERE id='$id'";
$data=mysqli_query($conn,$sql);
if($data)
{
//echo "Inserted data successfully";
header("location:displayadmin.php");
}
else
{
//echo "Not inserted";
echo "Not updated";
}
}else{
$folder=$folder.",".$folders2;
$sql="UPDATE `mpa_mulimg` SET `name`='$name',`email`='$email',`address`='$address',`phone`='$phone',`gender`='$gender',`degree`='$degree',`language`='$lang',`date`='$date',`dob`='$dob',`picsource`='$folder' WHERE id='$id'";
$data=mysqli_query($conn,$sql);
if($data)
{
//echo "Inserted data successfully";
header("location:displayadmin.php");
}
else
{
//echo "Not inserted";
echo "Not updated";
}
}
?>
displayclient.pgp
<?php
session_start();
include("connection.php");
if(!isset($_SESSION['cid'])){
header("location:login.php");
}else{
$cid= $_SESSION['cid'];
$sql="SELECT * FROM mpa_mulimg where id='$cid' ";
$data=mysqli_query($conn,$sql);
// $result=mysqli_fetch_assoc($data);//each and every attr value call.
// print_r($result);//print_r($result["name"]);
?>
<table border="1">
<tr>
<th>Sl.No.</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Phone</th>
<th>Password</th>
<th>Gender</th>
<th>Degree</th>
<th>Language</th>
<th>Date</th>
<th>D.O.B</th>
<th>Picture</th>
</tr>
<?php
$c=1;
while($result=mysqli_fetch_assoc($data))
{
?>
<tr>
<td><?php echo $c++; ?></td>
<td><?php echo $result["name"];?></td>
<td><?php echo $result["email"];?></td>
<td><?php echo $result["address"];?></td>
<td><?php echo $result["phone"];?></td>
<td><?php echo $result["password"];?></td>
<td><?php echo $result["gender"];?></td>
<td><?php echo $result["degree"];?></td>
<td><?php echo $result["language"];?></td>
<td><?php echo $result["date"];?></td>
<td><?php echo $result["dob"];?></td>
<td>
<?php
$arr = explode(",", $result["picsource"]);
?>
<img src='<?php echo $arr[0];?>' height="100" width="200">
<?php if(isset($arr[1])) { ?>
<img src="<?php echo $arr[1];?>" height="100" width="200">
<?php } ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
displayadmin.php
<?php
session_start();
include("connection.php");
if(!isset($_SESSION['aid'])){
header("location:login.php");
}else{
$aid=$_SESSION['aid'];
$sql="SELECT * FROM mpa_mulimg WHERE id!='$aid'";
$data=mysqli_query($conn,$sql);
// $result=mysqli_fetch_assoc($data);//each and every attr value call.
// print_r($result);//print_r($result["name"]);
?>
<table border="1">
<tr>
<th>Sl.No.</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Phone</th>
<th>Password</th>
<th>Gender</th>
<th>Degree</th>
<th>Language</th>
<th>Date</th>
<th>D.O.B</th>
<th>Picture</th>
<th>Action</th>
</tr>
<?php
$c=1;
while($result=mysqli_fetch_assoc($data))
{
?>
<tr>
<td><?php echo $c++; ?></td>
<td><?php echo $result["name"];?></td>
<td><?php echo $result["email"];?></td>
<td><?php echo $result["address"];?></td>
<td><?php echo $result["phone"];?></td>
<td><?php echo $result["password"];?></td>
<td><?php echo $result["gender"];?></td>
<td><?php echo $result["degree"];?></td>
<td><?php echo $result["language"];?></td>
<td><?php echo $result["date"];?></td>
<td><?php echo $result["dob"];?></td>
<td>
<?php
$arr = explode(",", $result["picsource"]);
?>
<img src='<?php echo $arr[0];?>' height="100" width="200">
<?php if(isset($arr[1])) { ?>
<img src="<?php echo $arr[1];?>" height="100" width="200">
<?php } ?>
</td>
<td>
<a href="edit.php?eid=<?php echo $result['id'];?>">edit</a><!--edit-->
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
Comments
Post a Comment