/    Sign up×
Community /Pin to ProfileBookmark

different $user system, help

i have a messaging system between users and i use:

[code=php]$user = MYSQL_QUERY(“SELECT * from users WHERE id=’$_COOKIE[id]’ AND password = ‘$_COOKIE[pass]'”);
$user = mysql_fetch_array($user);[/code]

to get users info but this script uses the below, if i just put my $user = it doesnt work, does anyone have any ideas, please help me.

[code=php]<?
$user = $_SESSION[‘username’];

include ‘db.php’;

//Are they logged in or not?
if(!$user)
{
echo “<br><p>you arent logged in</p><br>”;
}

else
{
//Get your private message count
//Find the percentage that your inbox is full
$sql = mysql_query (“SELECT pm_count FROM users WHERE username=’$user'”);
$row = mysql_fetch_array ($sql);
$pm_count = $row[‘pm_count’];

$percent = $pm_count/’50’;
$percent = $percent * ‘100’;
?>
<br>
<center>
<b><p><a href=”inbox.php”>Inbox</a> | <a href=”compose.php”>Compose</a> | <a href=”sent.php”>Sentbox</a></b>
<b><p><? echo “$pm_count”.” of 50 Total | “.”$percent”.”% full”; ?></p></b>
</center>
<br>
<?
//This stuff and the while loop will query, see if you have messages or not, and display them if you do
$query = “SELECT id, sender, subject, message FROM messages WHERE reciever=’$user'”;
$sqlinbox = mysql_query($query);

//Error thingy, ohh no! Dispaly the error and the query so we can diagnose the problem if there is one
if(!$sqlinbox)
{
?>
<p><? print ‘$query: ‘.$query.mysql_error();?></p>
<?
}

//There are no rows found for the user that is logged in, so I guess that means they dont have any messages or maybe its all broken
elseif (!mysql_num_rows($sqlinbox) )
{
?>
<center><p><b>You have no messages to display</b></p></center>
<?
}

//So if there is not an error, and they apparently do have messages we need to get their information and display it.
else
{
//Ok, Lets center this whole table Im going to make just because I like it like that
//Then we create a table 80% the total width with 3 columns The subject is 75% of the whole table, the sender is 120 pixels (should be plenty) and the select checkboxes only get 25 pixels
?>
<center>
<form name=”send” method=”post” action=”delete.php”>
<table width=”80%”>
<tr>
<td width=”75%” valign=”top”><p><b><u>Subject</u></b></p></td>
<td width=”120px” valign=”top”><p><b><u>Sender</u></b></p></td>
<td width=”25px” valign=”top”><p><b><u>Select</u></b></p></td>
</tr>
<?
//Set the number variable to 1, because I am going to be incrementing this and store the private message ids into an array, they get stored if they’re selected anyways.
$num = ‘1’;

//Ok cool, now we stick it all into an array and we will dispaly it now
while($inbox = mysql_fetch_array($sqlinbox))
{
//These are the variables we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it
$pm_id = $inbox[‘id’];
$sender = $inbox[‘sender’];
$subject = $inbox[‘subject’];
?>
<tr>
<td width=”75%” valign=”top”><p><a href=”viewmsg.php?msg_id=<? echo $pm_id; ?>”><? echo $subject; ?></a></p></td>
<td width=”120px” valign=”top”><p><? echo $sender; ?></p></td>
<td width=”25px” valign=”top”><input name=”pms[]” type=”checkbox” value=”<? echo $pm_id; ?>”></td>
</tr>
<?
//Increment the number because otherwise it would just replace what was already there
$num++;

//This ends the while loop
}
?>
<tr>
<td colspan=”3″><input type=”submit” name=”Submit” value=”Delete Selected”></td>
<td></td>
<td></td>
</tr>
</table>
</center>
<?
//So this ends the else to see if it is all ok and having messages or not
}

//This ends that first thing that checks if you are logged in or not
}
?>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mitchell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...