Jump to content


Photo

PHP actions won't work?

php

  • Please log in to reply
8 replies to this topic

#1 Pokebert

Pokebert

    Member

  • Members
  • PipPip
  • 18 posts

Posted 26 January 2013 - 04:24 PM

I can't get to get this code to display anything other than " |Compose | Inbox | and I can't seem to fins the issue in the code. Can someone help me with this? An example of this mail system can be seen at http://nintendoville...System/mail.php

<?PHP 

INCLUDE("dbconn.php"); 
$result1=MYSQL_QUERY("select * from users WHERE username='$username'") or DIE ("cant do it"); 
$row100 = MYSQL_FETCH_ARRAY($result1); 
?> 
<html>
<head>
<title>
NintendoVille - Mail
</title>
<meta name='viewport' content='width=320'>
<style>
body
{
background-color:#FFFFFF;
padding: 0px;
margin: 0px;
}
#topscreen
{
width: 320px;
height: 218px;
background-color:#FFFFFF;
}
#bottomscreen
{
width: 320px;
height: 400px;
background-color:#C8C8C8;
}
#marquee
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
#credits
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
#infos
{
width: 320px;
height: 60px;
background-color:#B0B0B0;
border-radius: 7px;
}
#text
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
</style>
</head>
<body>
<div id='topscreen'>
<img src="../NintendoVilleLogoBeta.jpg.jpg" width=320px height=217px>
</div>
<div id='bottomscreen'>
<br>
<center>| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> | </center>
<table cellpadding="1" cellspacing="1" height="300" width="320"> 
<tr><td align=center valign=top> 
<?PHP 
IF($action==compose) { 
ECHO "<form action=mail.php?action=compose2 method=post>"; 
ECHO "<table>"; 
ECHO "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>"; 
ECHO "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>"; 
ECHO "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>"; 
ECHO "<tr><td><button type=submit>Send Mail!</button></td></tr>"; 
ECHO "</table>"; 
ECHO "</form>"; 
} 
IF($action==compose2) { 
$subject or DIE("Subject Blank"); 
$message or DIE("Message Black"); 
$to or DIE("To blank"); 
$date = DATE(YmdHis); 


$create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status) 
VALUES ('$to','$username','$subject','$message','$date','unread')"; 
$create2 = MYSQL_QUERY($create) or DIE("A letter could not be sent to $to!"); 
ECHO("Message Sent to $to!"); 

} 
IF($action==inbox) { 
$result=MYSQL_QUERY("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or DIE ("cant do it"); 
ECHO "<table cellpadding=2 cellspacing=1 width=500 valign=top>"; 
WHILE ($row=MYSQL_FETCH_ARRAY($result)) { 
ECHO "<tr><td width=30>Mail:</td><td><a href=mail.php?action=veiw&mail_id=$row[mail_id]>$row[Subject]</a></td><td width=50> <a href=mail.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>"; 
} 
ECHO "</table>"; 
} 
IF($action==veiw) { 
$result=MYSQL_QUERY("select * from mail where UserTo='$username' and mail_id=$mail_id") or DIE ("cant do it"); 
$row=MYSQL_FETCH_ARRAY($result); 
IF($row[UserTo]==$username) { 
} ELSE { 
ECHO "<font face=verdana><b>This isn't your mail!"; 
EXIT; 
} 
$query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'"; 
$query or DIE("An error occurred resulting that this message has not been marked read."); 
ECHO "<table border = 1 bordercolor = black width = 50% align=center><tr><td>$row[Subject]</td><td>$row[UserFrom]</td></tr><tr><td colspan='2'>$row[Message]<br><a href=mail.php?action=compose&to=$row[UserFrom]&subject=RE:$row[Subject]>Reply</a></td></tr></table>"; 
$rs = MYSQL_QUERY("UPDATE mail SET status='read' WHERE mail_id='$mail_id'"); 
} 
IF($action==delete) { 
$query = MYSQL_QUERY("DELETE FROM mail WHERE mail_id='$id' LIMIT 1"); 
IF($query) { 
ECHO "<font face=verdana>Message Deleted.</font>"; 
} ELSE { 
ECHO "The message wasnt deleted."; 
} 
} 
?> 
<br>
</div>
</body>
</html>


#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,377 posts
  • LocationCheshire, UK

Posted 26 January 2013 - 04:54 PM

String values like "compose" and "delete" should be enclosed in quotes (as I did), unless you have defined them as constants, but no sign of that. And where is $action variable's value defined?

try adding
var_dump($action);
and see what it contains

Edited by Barand, 26 January 2013 - 04:56 PM.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 trq

trq

    Advanced Member

  • Administrators
  • 31,020 posts
  • LocationSydney, Australia.

Posted 26 January 2013 - 05:12 PM

Turn error reporting on. PHP will point out your errors.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#4 Pokebert

Pokebert

    Member

  • Members
  • PipPip
  • 18 posts

Posted 26 January 2013 - 05:21 PM

Fixed undefined constants; now I just need to define actions.

#5 Pokebert

Pokebert

    Member

  • Members
  • PipPip
  • 18 posts

Posted 26 January 2013 - 05:38 PM

Code is now:

<?PHP

INCLUDE("dbconn.php");
$result1=MYSQL_QUERY("select * from users WHERE username='$username'") or DIE ("cant do it");
$row100 = MYSQL_FETCH_ARRAY($result1);

ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<html>
<head>
<title>
NintendoVille - Mail
</title>
<meta name='viewport' content='width=320'>
<style>
body
{
background-color:#FFFFFF;
padding: 0px;
margin: 0px;
}
#topscreen
{
width: 320px;
height: 218px;
background-color:#FFFFFF;
}
#bottomscreen
{
width: 320px;
height: 400px;
background-color:#C8C8C8;
}
#marquee
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
#credits
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
#infos
{
width: 320px;
height: 60px;
background-color:#B0B0B0;
border-radius: 7px;
}
#text
{
width: 320px;
height: 20px;
background-color:#B0B0B0;
border-radius: 7px;
}
</style>
</head>
<body>
<div id='topscreen'>
<img src="../NintendoVilleLogoBeta.jpg.jpg" width=320px height=217px>
</div>
<div id='bottomscreen'>
<br>
<center>| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> | </center>
<table cellpadding="1" cellspacing="1" height="300" width="320">
<tr><td align=center valign=top>
<?PHP
IF($action=='compose') {
ECHO "<form action=mail.php?action=compose2 method=post>";
ECHO "<table>";
ECHO "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>";
ECHO "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>";
ECHO "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>";
ECHO "<tr><td><button type=submit>Send Mail!</button></td></tr>";
ECHO "</table>";
ECHO "</form>";
}
IF($action=='compose2') {
$subject or DIE("Subject Blank");
$message or DIE("Message Black");
$to or DIE("To blank");
$date = DATE(YmdHis);



$create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status)
VALUES ('$to','$username','$subject','$message','$date','unread')";
$create2 = MYSQL_QUERY($create) or DIE("A letter could not be sent to $to!");
ECHO("Message Sent to $to!");

}
IF($action=='inbox') {
$result=MYSQL_QUERY("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or DIE ("cant do it");
ECHO "<table cellpadding=2 cellspacing=1 width=500 valign=top>";
WHILE ($row=MYSQL_FETCH_ARRAY($result)) {
ECHO "<tr><td width=30>Mail:</td><td><a href=mail.php?action=veiw&mail_id=$row[mail_id]>$row[Subject]</a></td><td width=50> <a href=mail.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>";
}
ECHO "</table>";
}
IF($action=='veiw') {
$result=MYSQL_QUERY("select * from mail where UserTo='$username' and mail_id=$mail_id") or DIE ("cant do it");
$row=MYSQL_FETCH_ARRAY($result);
IF($row[UserTo]==$username) {
} ELSE {
ECHO "<font face=verdana><b>This isn't your mail!";
EXIT;
}
$query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'";
$query or DIE("An error occurred resulting that this message has not been marked read.");
ECHO "<table border = 1 bordercolor = black width = 50% align=center><tr><td>$row[Subject]</td><td>$row[UserFrom]</td></tr><tr><td colspan='2'>$row[Message]<br><a href=mail.php?action=compose&to=$row[UserFrom]&subject=RE:$row[Subject]>Reply</a></td></tr></table>";
$rs = MYSQL_QUERY("UPDATE mail SET status='read' WHERE mail_id='$mail_id'");
}
IF($action=='delete') {
$query = MYSQL_QUERY("DELETE FROM mail WHERE mail_id='$id' LIMIT 1");
IF($query) {
ECHO "<font face=verdana>Message Deleted.</font>";
} ELSE {
ECHO "The message wasnt deleted.";
}
}
?>
<br>
</div>
</body>
</html>

And i fixed undefined constants but still get:
Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 75

Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 86

Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 101

Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 110

Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 124


So how should I fix this? And since I'm very new to PHP could I get an example piece of coding?

Edited by Pokebert, 26 January 2013 - 05:39 PM.


#6 Pokebert

Pokebert

    Member

  • Members
  • PipPip
  • 18 posts

Posted 26 January 2013 - 06:10 PM

String values like "compose" and "delete" should be enclosed in quotes (as I did), unless you have defined them as constants, but no sign of that. And where is $action variable's value defined?

try adding

var_dump($action);
and see what it contains


Where should I insert var_dump? I'm new to PHP...

#7 trq

trq

    Advanced Member

  • Administrators
  • 31,020 posts
  • LocationSydney, Australia.

Posted 26 January 2013 - 06:13 PM

You haven't defined $action anywhere. No point var_dumping it, it doesn't exist.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#8 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,377 posts
  • LocationCheshire, UK

Posted 26 January 2013 - 06:15 PM

Between these two lines below would be as good a place as any

<?PHP
IF($action=='compose') {

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#9 Pokebert

Pokebert

    Member

  • Members
  • PipPip
  • 18 posts

Posted 26 January 2013 - 06:31 PM

I'll try to develop a different PM system for my website. Marked as resolved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com