Jump to content

IDK how to ....


techiefreak05

Recommended Posts

I'm creating a message system on my site, which works fine, but theres one thing, letting a user know they have new messages!  I think i'd use this somewhere...
[code]SELECT * FROM `messages` WHERE `to` = '$to' AND `status` = 'no'[/code]

the variable "$to" will be defined, it will be $to = '$_SESSION[username]'

I want to echo "New Messages" if anywhere in the "status" column equals "no" , how would I do this?
Link to comment
Share on other sites

[code]
$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");
if (!$result) {
  echo 'Could not run query: ' . mysql_error();
  exit;
}
$row = mysql_fetch_row($result);
$new = $row[0];
if($new == "")
{
$new = "0";
}
if(new != "0" )
{
echo "You have $new new messages.";
}
[/code]
umm try this
Link to comment
Share on other sites

I used this
[code]$to = '$_SESSION[username]'
$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");
if (!$result) {
  echo 'Could not run query: ' . mysql_error();
  exit;
}
$row = mysql_fetch_row($result);
$new = $row[0];
if($new == "")
{
$new = "0";
}
if(new != "0" )
{
echo "<font color=red><b>You have $new new messages!</b></font>";
}[/code]

and got this error:
[code]Parse error: syntax error, unexpected T_VARIABLE in /home/zyco/public_html/newlayout/main.php on line 32[/code]
Link to comment
Share on other sites

here is LINES 27 - 47(the whole PHP script)

[code]  <?php
if($logged_in){
headerLinks();
$to = '$_SESSION[username]';
$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");
if (!$result) {
  echo 'Could not run query: ' . mysql_error();
  exit;
}
$row = mysql_fetch_row($result);
$new = $row[0];
if($new == "")
{
$new = "0";
}
if(new != "0" )
(43){
echo "<font color=red><b>You have $new new messages!</b></font>";
}
}
?>[/code]
Link to comment
Share on other sites

remove the
$to = '$_SESSION[username]';
quotes
make it
$to = $_SESSION['username']; thats where i think the error is thats all i can see o my bad i see ur
and ur missing

o sorry i mis read it instead of doing
if($logged_in){
and than } at the end
try
if(!$logged_in){
echo"please login";
exit;
}
Link to comment
Share on other sites

I still get the same error:
[code]Parse error: syntax error, unexpected T_IS_NOT_EQUAL, expecting T_STRING or T_VARIABLE or '$' in /home/zyco/public_html/newlayout/main.php on line 41[/code]

with this as my updated code:
[code]  <?php
if($logged_in){
headerLinks();
$to = $_SESSION[username];
$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");
if (!$result) {
  echo 'Could not run query: ' . mysql_error();
  exit;
}
$row = mysql_fetch_row($result);
$new = $row[0];
if($new = ""){
$new = "0";
}
if(new != "0" ){
echo "<font color=red><b>You have $new new messages!</b></font>";
}
}
?>[/code]

LINE 41 IS:
[code]if(new != "0" ){[/code]
Link to comment
Share on other sites

i dont see any error on that line try updating the code to this
[code]
<?php
if(!$logged_in){
echo"Please Log-in";
exit;
}
headerLinks();
$to = $_SESSION['username'];
$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);
$new = $row[0];
if($new = ""){
$new = "0";
}
if(new != "0"){
echo "<font color='red'><b>You have $new new messages!</b></font>";
}
?>
[/code]
im pretty sure this will work
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.