Jump to content

If Inbox > 1(unread) how to?


morrisjohnny

Recommended Posts

Parse error: syntax error, unexpected '{' in /home2/jnymris/public_html/Maffia (05-05-05)/Info.php on line 12
I'm getting sick of this, i'm posting now but i'll check in the morning since i really can't be bothered anymore
<?php$link = mysql_connect('localhost', 'jnymris_mozza', 'qwerty######er');mysql_select_db(inbox);if (!$link) {   die('Could not connect: ' . mysql_error());}mysql_select_db("Inbox");$sql = "SELECT * FROM inbox WHERE reciever='$cookieusername' AND unread='0'";$result = mysql_query($sql);$messag = "0";while($row = mysql_num_rows($result){$messag++;}  echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";}mysql_close($link);?>

Link to comment
Share on other sites

Replace this:mysql_select_db("Inbox");with this:mysql_select_db("Inbox") or echo mysql_error();And replace this:$result = mysql_query($sql);with this:$result = mysql_query($sql) or echo mysql_error();And see if you get a different error. Keep in mind that this is not the table name (Inbox might be the table name), it is the name of the database that contains the table.

$messag = "0";while($row = mysql_num_rows($result){$messag++;}
Even though it is missing a closing paren on the while statement, that will actually result in an infinite loop, so you don't want to do that. mysql_num_rows works fine if the query succeeded. The error message indicates that the query didn't even succeed, not that there is a problem with mysql_num_rows.
Link to comment
Share on other sites

You have an extra } at the end of this:

while($row = mysql_num_rows($result){$messag++;}  echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";}

so just remove it like this:

while($row = mysql_num_rows($result){$messag++;}  echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";

:)

Link to comment
Share on other sites

You're also missing a closing paren here:while($row = mysql_num_rows($result)But like I said, you don't want to execute this code, because it will never stop executing. mysql_num_rows will either be zero and the loop will never run, or it will be non-zero and the loop will never stop. The value of mysql_num_rows never changes in this context.

Link to comment
Share on other sites

My database name i think is "jnymris_mozza" but i uploaded a file to mysql called "maffia MYSQL.sql"Anyway i now recive a new error

Parse error: syntax error, unexpected T_ECHO in /home2/jnymris/public_html/Maffia (05-05-05)/Info.php on line 7
<?php$link = mysql_connect('localhost', 'jnymris_mozza', '***');mysql_select_db(jnymris_mozza);if (!$link) {   die('Could not connect: ' . mysql_error());}mysql_select_db("jnymris_mozza") or echo mysql_error();$sql = "SELECT * FROM inbox WHERE reciever='$cookieusername' AND unread='0'";$result = mysql_query($sql) or echo mysql_error();$messag = "0";while($row = mysql_num_rows($result){$messag++;}  echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";mysql_close($link);?>

Link to comment
Share on other sites

Whoops, I guess I gave you bunk code. I didn't realize you couldn't use echo in that context. Change lines 7-9 to this:mysql_select_db("jnymris_mozza") or exit(mysql_error());$sql = "SELECT * FROM inbox WHERE reciever='$cookieusername' AND unread='0'";$result = mysql_query($sql) or exit(mysql_error());It will stop execution of the page if you have a database error, which is probably better for debugging anyway. You may want to remove the exit statements once you get the code working properly.Also, remove the first mysql_select_db statement on line 3 right under the mysql_connect statement.

Link to comment
Share on other sites

Replace this:$messag = "0";while($row = mysql_num_rows($result){$messag++;}with this:$messag = mysql_num_rows($result);It looks like all of the database connectivity and also the query itself is working, so mysql_num_rows won't complain.

Link to comment
Share on other sites

Okay now it shows Inbox [0] or Inbox [1] if u have one unread, This will be suitable although i don't surpose u know how i could make it say "You Have New Mail" if one mail is unread and say nothing if their is no new mail?Thanks though Thts awesome the way u have done that

Link to comment
Share on other sites

This is your output statement:echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";So you can change that to say anything you want. You know that $messag holds the number of unread messages. So, you can do whatever you want:

if ($messag == 0)  echo "No new messages";else  echo "<a href =\"inbox.php\" target =\"showframe\">Inbox [{$messag} new]</a>";

etc. Since you know how many new messages there are, you can do whatever else you want with that information.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...