hi i have followed a friends tutorial for my website and all is working upon production but when im attempting to add it to my site im having problems getting the following to show up in my page none of the links in the php block are showing up ive even ended the php block before the a href and removed the echo ""; and opened php up after and the links still dont show can someone check whats going off

<table width="150" border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
        <td class="trtc" valign="top">
            <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
               <td><img src="images/image27.jpg">&nbsp;&nbsp;<a href="#">Send Message</a></td>
            </tr>
            <tr>
               <td><img src="images/favourites.jpg">&nbsp;&nbsp;<a href="#">Add To Favourites</a></td>
            </tr>
            <td>
            <img src="images/image25.png">&nbsp;&nbsp;<?php
if($user != $my_id) {
    $check_frnd_query = mysqli_query($conn,"SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$user') OR (user_one='$user' AND user_two='$my_id')");
    if(mysqli_num_rows($check_frnd_query) == 1){
        echo "<a href='#' class='box'>Already Friends</a> | <a href='actions.php?action=unfriend&user=$user' class='box'>Remove $username From Friend</a>";
    } else {
        $from_query = mysqli_query($conn,"SELECT `id` FROM `friend_req` WHERE `from`='$user' AND `to`='$my_id'");
        $to_query = mysqli_query($conn,"SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to`='$user'");
        if(mysqli_num_rows($from_query) == 1) {
          echo "<a href='actions.php?action=ignore&user=$user' class='box'' class='box'>Ignore Request</a> | <a href='actions.php?action=accept&user=$user' class='box'>Accept Request</a>";  
        } else if (mysqli_num_rows($to_query) == 1) {
          echo "<a href='actions.php?action=cancel&user=$user' class='box'>Cancel Request</a>";  
        } else {
          echo "<a href='actions.php?action=send&user=$user' class='box'>Send Request</a>";  
        }
    }
}
?>
</td>
            </tr>
            <tr>
               <td><img src="/images/block.png">&nbsp;&nbsp;<a href="#">Block User</a></td>
            </tr>
            <tr>
               <td><img src="images/report.jpg">&nbsp;&nbsp;<a href="#">Report User</a></td>
            </tr>
                </table>

much appreicated jan x

It looks like the PHP code may not be executing. Does your file have the .PHP extension, not .HTML or anything else?

Either that or there's an issue with your variables. if($user != $my_id), none of these are defined in your script, for example, so all your mySQL queries would be failing. However, that should give a fatal error, so if you are seeing something it's unlikely to be this. Check your error logs to be sure.

Member Avatar

diafol

As a general thing, you should always avoid injecting big chunks of code into HTML. Only do minimal echo, condition and loop in HTML blocks. This method of building sites will cause HUGE maintenace issues. Tidy away functions into their own include files. For example:

require ABOVEDIR . "/includes/mysqli.php";
require ABOVEDIR . "functions/friends.php";
$link = (isset($user)) ? getFriendLink($user) : "";

Then

<td>
            <img src="images/image25.png">&nbsp;&nbsp;<?=$link?>
</td>

ty hun been away for a day but ill have a look at that now :) x