-
Notifications
You must be signed in to change notification settings - Fork 1
/
deleteroommate.php
51 lines (42 loc) · 1.25 KB
/
deleteroommate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
$con=mysqli_connect('127.0.0.1','root','123456');
if(!$con)
{
echo 'Connection error';
}
if(!mysqli_select_db($con,'project'))
{
echo 'Database not selected';
}
session_start();
$vemail=$_SESSION['lemail'];
$roomno=$_POST['delroommatenum'];
$_SESSION['sessionroomno']=$roomno;
echo 'ROOMATE NO.'.$roomno;
$sql="SELECT count(*) FROM roommate where rpwfid=(SELECT pwfid FROM pwf WHERE email='$vemail')";
$roomquery=mysqli_query($con,$sql);
$roomrow=mysqli_fetch_assoc($roomquery);
$roomcount=$roomrow['count(*)'];
if($roomno > $roomcount)
{
echo "INSIDE IF";
echo "<script>alert('You dont have that roomate!!');</script>";
header("refresh:0;url=selectrm.html");
}
else
{
$sql="DELETE FROM roommate WHERE rmno='$roomno' AND rpwfid=(SELECT pwfid FROM pwf WHERE email='$vemail')";
if(mysqli_query($con,$sql))
{
for($i=$roomno;$i<=$roomcount;$i++)
{
$j=$i-1;
$sql="UPDATE roommate SET rmno='$j' WHERE rmno='$i' AND rpwfid=(SELECT pwfid FROM pwf WHERE email='$vemail')";
$row=mysqli_query($con,$sql);
//echo "updated rmno".$i."to".$j."<br>";
}
echo "<script>alert('Roommate deleted');</script>";
header("refresh:0;url=selectrm.html");
}
}
?>