3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //************************************************************* // place $req_status any where it will show the button/msg etc //************************************************************* //$user_email = email@example.com // get id by matching email address $result = mysql_query("SELECT id FROM tbluser WHERE email = '$user_email'"); if (!$result) { echo 'Could not run query'; } $row = mysql_fetch_assoc($result); $user_id = $row['id']; // id of the user //logged in. I assumed that you have the user id and profile id as follows. //$_SESSION['user_id'] = $user_id; if($_GET['fid']){ // ---------------------------------------------------- $friend_id = $_GET['fid']; // profile user id. // it shows "Friends" if user is friend. or "Add friend" or "Request pending" $query1="SELECT * FROM friends WHERE (user_id = '$user_id' AND friend_id = '$friend_id') OR (friend_id = '$friend_id' AND user_id = '$user_id')"; $result = mysql_query($query1); $row = mysql_num_rows($result); if ($row == 1) { // exist, whether it's active or not while($row = mysql_fetch_assoc($result)) { if ($row['status'] == 1) { echo "Friends"; } elseif ($row['status'] == 0) { if($row['user_id'] == $user_id){ $req_status = "Request pending"; //echo "Request pending"; } elseif($user_id == $row['friend_id']) { $uid = $row["user_id"]; $req_status = '<a href="add_friend.php?fid=$uid">Accept request</a> or <a href="ignore_request.php?fid=$uid">Ignore</a>'; } } else { if($row['user_id'] == $user_id){ $req_status = "Request pending"; //echo "Request pending"; } else { $req_status = '<a href="add_friend.php?fid='.$friend_id.'">Add Friend</a>'; //echo "<a href='add_friend.php?fid=".$friend_id."'>Add Friend</a>"; } } } } else { // if the relationship don't exist $req_status = '<a href="add_friend.php?fid=$friend_id">Add friend</a>'; //echo "<a href='add_friend.php?fid=".$friend_id."'>Add friend</a>"; } // ---------------------------------------------------- } ?>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function mysql_query() in /in/X05JH:10 Stack trace: #0 {main} thrown in /in/X05JH on line 10
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function mysql_query() in /in/X05JH on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Notice: Undefined variable: user_email in /in/X05JH on line 10 Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /in/X05JH on line 10 Warning: mysql_query(): A link to the server could not be established in /in/X05JH on line 10 Could not run query Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /in/X05JH on line 14 Notice: Undefined index: fid in /in/X05JH on line 22
Output for 4.3.0 - 4.3.1
Notice: Undefined variable: user_email in /in/X05JH on line 10 Warning: mysql_query() [http://www.php.net/function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /in/X05JH on line 10 Warning: mysql_query() [http://www.php.net/function.mysql-query]: A link to the server could not be established in /in/X05JH on line 10 Could not run query Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /in/X05JH on line 14 Notice: Undefined index: fid in /in/X05JH on line 22