Test Setup Failed
Push — master ( a87e27...976b69 )
by Ankit
02:24
created

account.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<!Doctype html>
2
<html>
3
4
5
<?php
6
session_start();
7
include 'database.php';
8
$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
9
$user=explode("/", $_SERVER['REQUEST_URI']);
10
$user = $user[count($user)-1];
11
var_dump($user);
12
if(isset($_SESSION['start']) and !$user)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
13
{
14
	$login_id=$_SESSION['start'];
15
	$query="SELECT username from login where login_id='$login_id'";
16
	if($result=$connect->query($query))
17
	{
18
		if($result->num_rows >0)
19
		{
20
			$row=$result->fetch_assoc();
21
			$location="http://localhost/openchat/account.php/".$row['username'];
22
			header("Location:".$location);
23
		}
24
	}
25
26
}
27
28
else if($user)
29
{
30
	$query="SELECT * from login where username='$user'";
31
	if($result=$connect->query($query))
32
	{
33
		if($result->num_rows >0)
34
		{
35
			$row=$result->fetch_assoc();
36
			$id=$row['login_id'];
37
			$query="SELECT * from profile where login_id='$id'";
38
			if($result=$connect->query($query))
39
			{
40
				if($result->num_rows>0)
41
				{
42
					$r=$result->fetch_assoc();
43
					$row=array_merge($row,$r);
44
					// var_dump($row);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
				}
46
			}
47
			else
48
			{
49
				die("error");
50
			}
51
?>
52
	<head>
53
		<title>OpenChat || Profile</title>
54
        <link rel="stylesheet" href="../css/profile.css">
55
	</head>
56
57
58
59
	<body>
60
61
		<div class="header">
62
            <a id="brand" href="">OpenChat</a>
63
            <ul class="nav-right">
64
                <li><a href="../index.php">About</a></li>
65
                <?php if(isset($_SESSION['start']))
66
				{
67
				?>
68
				<li><a href="../message.php">Message</a></li>
69
				<li><a href="../registration-module/source/class.logout.php">Log out</a></li>
70
				<?php
71
				}
72
				else
73
				{
74
				?>
75
				<li><a href="../login.php">Login</a></li>
76
				<li><a href="../register.php">Register</a></li>
77
				<?php
78
				}
79
				?>
80
            </ul>
81
        </div>
82
83
84
85
86
        <div class="main">
87
			<div class="boxx" >
88
89
				<div class="pic">
90
					<img src="../ankit.png">
91
				</div>
92
93
				<div class="brief">
94
					<h1 id="name">Name: <?php echo $row['name']; ?></h1><br>
95
					<?php foreach ($row as $key => $value) {
96
						if($key=='username' and $value!=null)
97
							echo '<p>Username: '.$row["username"] .'</p><br>';
98
						if($key=='email' and $value!=null)
99
							echo '<p>Email Id: '.$row["email"] .'</p><br>';
100
						if($key=='status' and $value!=null)
101
							echo '<p>Status: '.$row["status"] .'</p><br>';
102
						if($key=='education' and $value!=null)
103
							echo '<p>Education: '.$row["education"] .'</p><br>';
104
						if($key=='gender' and $value!=null)
105
							echo '<p>Gender: 	'.$row["gender"] .'</p><br>';
106
					}
107
					?>
108
				</div>
109
				<?php if($_SESSION['start']==$row['login_id'])
110
				{
111
					?>
112
				<div class="edit"><a href="#">Edit Profile</a></div>
113
				<?php
114
				}
115
				?>
116
			</div>
117
118
			<?php
119
			if($_SESSION['start']==$row['login_id'])
120
			{
121
				?>
122
123
			<div class="boxx" id="profile">
124
				<form method="post" action="../profile_generate.php">
125
					<label>Status : </label>
126
					<textarea name="status" id="status"><?php echo $row['status']; ?></textarea>
127
					<label>Education : </label>
128
					<input type="text" name="education" id="education" value="<?php echo $row['education']; ?>"></input>
129
					<label>Gender : </label><br>
130
					<input type="radio" name="gender" id="gender" value="Male" <?php echo ($row['gender']=='Male')?'checked':'' ?>> Male<br>
131
					<input type="radio" name="gender" id="gender" value="Female" <?php echo ($row['gender']=='Female')?'checked':'' ?>> Female<br>
132
					<input type="submit" name="submit" value="Done" id="submit">
133
				</form>
134
			</div>
135
			<?php
136
			}
137
			?>
138
		</div>
139
140
141
		<div class="footer">
142
			<h3 class="footer_text">Made with love by <a href="#">Ankit Jain</a></h3>
143
		</div>
144
145
	</body>
146
    <script type="text/javascript" src="../js/jquery-3.0.0.min.js"></script>
147
	<script type="text/javascript" src="../js/profile.js"></script>
148
    <script type="text/javascript" src="../placeholder.js/placeholder.js"></script>
149
150
151
</html>
152
153
154
155
<?php
156
		}
157
		else
158
		{
159
			die("Invalid User");
160
		}
161
	}
162
	else
163
	{
164
		die("invalid");
165
	}
166
}
167
else
168
{
169
	header("Location:http://localhost/openchat/index.php");
170
}
171
?>
172
173