Member Avatar for david.roun.7_1

So, I checked the first 5 pages and couldn't find anything like what I'm asking. When a user registers on my site, it automatically creates a new directory and uploads a picture of their choice, to the directory. When the user logs in, the webpage shows their photo, taken from the new directory, and is supposed to show the photo of everyone else registered. It doesn't, only the picture of the person logged in. The two pieces of code are exactly the same, except that one says name!=$name and the other is the name of the user. I thought it was the database but it is displaying other information from it. Please help.

session_start();
require('connect/connect.php');


$name=$_SESSION['name'];
echo '<table id="intro"><b>';
echo '<tr><td>Welcome: ' . $_SESSION['name'] . '</td></tr>';
echo '<tr><td>Your Login Id is: ' . $_SESSION['loginid'] . '</td></tr>';

echo '</b></table>';
echo '<br>A photo about me:<br><br>';


$dresult=mysql_query("SELECT description,photo FROM demographics WHERE name='$name'") or DIE(mysql_error());


while($drow=mysql_fetch_array($dresult)){
$image=$drow['photo'];

echo '<img src="pages/' . $name . '/' . $image . '" style="height:20%; width:30%;"/><br>';
echo '<p>Why this photo represents me</p>';
echo $drow['description'];

}

?>
<br><br>
<a href="login/inputupdate.php">I want to update my information</a><br> 

<div id="right">
<?php

echo '<p>Here are others registered for the site:</p>';

$result=mysql_query("SELECT name,photo,lastlogin FROM demographics WHERE name!='$name'") or DIE(mysql_error());

while($row=mysql_fetch_array($result)){
echo '<table>';
$image=$row['photo'];
echo '<tr><td><img src="pages/' . $name . '/' . $image . '"style="height:20%; width:30%;"/></td></tr>';
echo '<tr><td>' . $row['name'] . '</td></tr>';
echo '<tr><td>Last Login: ' . date('M d Y', strtotime($row['lastlogin'])) . '</td></tr></table>';
}
?>

I rewrote you code so I could read better, and the only thing I see is the missing file extention.

<?php 


    session_start();
    require('connect/connect.php');

    $name = $_SESSION['name']; ?>

        <table id="intro">
            <tr>
                <td><strong>Welcome: <?php echo $_SESSION['name']; ?></strong></td>
                <td><strong>Your Login Id is: <?php echo $_SESSION['loginid']; ?></strong></td>
            </tr>
        </table>
        <p>A photo about me:</p>

        <?php $dresult = mysql_query("SELECT `description`, `photo` FROM `demographics` WHERE `name` = '$name'") or DIE(mysql_error()); ?>

        <?php while($drow = mysql_fetch_array($dresult)): ?>
                <?php $image = $drow['photo']; ?>
                <p><img src="/pages/<?php echo $name; ?>/<?php echo $drow['photo']; ?>.jpg" alt="<?php echo $drow['description']; ?>"  style="height:20%; width:30%;" /></p>
                <p>Why this photo represents me.</p>
                <p><?php echo $drow['description']; ?></p>
        <?php endwhile; ?>
        <br /><br />
        <a href="login/inputupdate.php">I want to update my information</a><br>
        <div id="right">
            <p>Here are others registered for the site:</p>
            <?php $result = mysql_query("SELECT `name`, `photo`, `lastlogin` FROM `demographics` WHERE `name` != '$name'") or die(mysql_error()); ?>
            <?php while($row = mysql_fetch_array($result)): ?> 
            <table>
                <tbody>
                    <tr>
                        <td><img src="/pages/<?php echo $name; ?>/<?php echo $row['photo']; ?>" alt="<?php echo $row['name']; ?>.jpg" style="height:20%; width:30%;" /></td>
                    </tr>
                    <tr>
                        <td><?php echo $row['name']; ?></td>
                    </tr>
                    <tr>
                        <td>Last Login: <?php echo date("M D Y", strtotime($row['lastlogin'])); ?></td>
                    </tr>
                </tbody>
            </table>
            <?php endwhile; ?>
        </div>
Member Avatar for david.roun.7_1

The file extension is listed in the database, I didn'tput the picture in the database, just something that points to it (below is from the database).

user name user id password description dob photo last login
test2 test2 some pword test2 test2 christmas2010.jpg 2014-02-01

The picture goes into the folder that is created when the user registers. Thanks for showing me a better way to organize the code.

Try this: "SELECT name, photo, lastlogin FROM demographics WHERE name <> '$name'"

Member Avatar for david.roun.7_1

No change. I don't get it. It works when I do it on XAMPP but not on the live site.

var_dump() results and post what you get?

Member Avatar for david.roun.7_1

string(7) "dog.jpg" for each picture (although the number changes).

var_dump($imgage);

ok, so we def know its your query. Try this: "SELECT name, photo, lastlogin FROM demographics WHERE NOT name = '$name'"

Member Avatar for david.roun.7_1

I didn't know that about var_dump(), but now I'll use it to see if the code is working. Thanks. I don't know what's wrong. I tried changing the query to SELECT *, tried WHERE NOT, !=, <>, changed the name of the $image variable to $imge (thought it was confusing the computer), moved the $_SESSION['$name'] variable down, moved the require() command down to where the code was, changed the $row[] variable, all with no success.

<?php
$result=mysql_query("SELECT name,photo,lastlogin FROM demographics WHERE NOT name='$name'") or DIE(mysql_error());

while($row=mysql_fetch_array($result)){
$imge=$row['photo'];
echo '<table>';
echo '<tr><td><img src="pages/' . $name . '/' . $imge . '"/></td></tr>';
echo '<tr><td>' . $row['name'] . '</td></tr>';
echo '<tr><td>Last Login: ' . date('M d Y', strtotime($row['lastlogin'])) . '</td></tr></table>';
}
?>
Member Avatar for david.roun.7_1

Got it. I had to re-declare the variables after I used them the first time. Thank you for all your help.

$presult=mysql_query("SELECT name,photo,lastlogin FROM demographics WHERE name!='$name'") or DIE(mysql_error());
while($prow=mysql_fetch_array($presult)){
$imge=$prow['photo'];
$pname=$prow['name'];
echo '<table>';
echo '<tr><td><img src="pages/' . $pname . '/' . $imge . '"/></td></tr>';
echo '<tr><td>' . $row['name'] . '</td></tr>';
echo '<tr><td>Last Login: ' . date('M d Y', strtotime($row['lastlogin'])) . '</td></tr></table>';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.