3v4l.org

run code in 300+ PHP versions simultaneously
<?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>'; //echo "<a href='add_friend.php?fid=".$row['user_id']."'>Accept request</a> or <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.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function mysql_query() in /in/M8R3r:10 Stack trace: #0 {main} thrown in /in/M8R3r on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28
Fatal error: Call to undefined function mysql_query() in /in/M8R3r on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Notice: Undefined variable: user_email in /in/M8R3r on line 10 Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /in/M8R3r on line 10 Warning: mysql_query(): A link to the server could not be established in /in/M8R3r on line 10 Could not run query Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /in/M8R3r on line 14 Notice: Undefined index: fid in /in/M8R3r on line 22
Output for 4.3.0 - 4.3.1
Notice: Undefined variable: user_email in /in/M8R3r 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/M8R3r on line 10 Warning: mysql_query() [http://www.php.net/function.mysql-query]: A link to the server could not be established in /in/M8R3r on line 10 Could not run query Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /in/M8R3r on line 14 Notice: Undefined index: fid in /in/M8R3r on line 22

preferences:
228.62 ms | 402 KiB | 349 Q