Jump to content

Switches and PROBLEMS.


Cetanu

Recommended Posts

Okay, someone's going to need to help me before I through some swords through my laptop screen and then chuck the carcass of the computer at my little brother.

 

This PM script WILL NOT work and I've spent 2 hours on it. I cannot fix it!

<?php 
session_start(); 
include "db.php";

switch($_GET['sa']){
default:
inbox();
break;

case 'send':
send();
break;

case 'sent':
sent();
break;

case 'msg':
msg();
break;
}

echo"<br />
<a href='pmindex.php'>Inbox</a><br/>
<a href='pmindex.php?action=messages&sa=send'>Compose</a>
<br />";

function inbox(){
print "
<br/><h2>Inbox</h2><table width='100%' class='content'>";

print "<tr><td width='35%'><h3>From</h3></td><td width='55%'><h3>Subject</h3></td><td><h3>Content</h3></td></tr>";

$m=mysql_query("SELECT * FROM messages WHERE `to_userid`='{$_SESSION['username']}'") or die(mysql_error());
while($mail=mysql_fetch_array($m))
{
$from=$mail['from_userid'];
$id=$mail['id'];
$subject=$mail['subject'];

  echo "<tr><td><a href='profile.php?username=$from'>$from</a></td><td><a href='pmindex.php?action=messages&sa=msg&id=$id'>$subject</a></td>";
  echo $_POST['content'];
  echo "<br/><br/><td><a href='pmindex.php?action=messages&go=delete'>Delete</a></td></tr>";
}
echo "</table>";
}



function msg(){
$id=$_GET['id'];
print "<table>";

$ms=mysql_query("SELECT * FROM messages WHERE `to_userid`='{$_SESSION['username']}' AND `id`='$id'") or die(mysql_error());
   

$mamessage=$ms[content];
$msubject=$ms[subject];
$from=$ms[from_userid];

echo "$msubject<br />";

echo "<b>Sent By:</b> <a href='pmindex.php?action=profile&username=$from'>$from</a><br/>
<b>Message:</b><br/>
$mamessage</div><br/>";


print "</table>";

if($_POST['reply']){

   $message=$_POST['content'];

   $subject=$_POST['subject'];
   $to=$_POST['from_userid']; 

      $reply="INSERT INTO messages SET `from_userid`='{$_SESSION['username']}',`to_userid`='$to',`subject`='$subject',`content`='$message',`id`='$id'";

      mysql_query($reply) or die("Could not reply");

   echo'<div class="done">Message Sent!</div><br />';
}

echo "<table><div class='header'>Reply</div><br />";

echo "<form action=\"pmindex.php?action=messages&sa=msg&id=$id\" method=\"post\">

<div class='content'>
   Subject:<br>

   <input type='text' name='subject' size='20' value='Re: $subject'><br>

   Message:<br>

   <textarea name='content' rows='6' cols='40'></textarea><br>

   <input type='submit' name='reply' value='Reply'></form></div></table>";



}



function send(){
if($_POST['send']){

   $to=$_POST['to_userid'];

   $message=$_POST['content'];

   $subject=$_POST['subject'];

   $to=$_POST['to_userid'];

      $send="INSERT INTO messages SET `from_userid`='{$_SESSION['username']}',`to_userid`='$to',`subject`='$subject',`content`='$message'";

      mysql_query($send) or die(mysql_error());

   echo "Message Sent!<br />";
}

print "<table>

<div class='header'>Send</div><br />";

$to=$_GET['to_userid'];

   echo "<form action=\"pmindex.php?action=messages&sa=send\" method=\"post\">

   To:<br>
   <input type='text' name='to_userid' size='20' value='$to'><br/>

   Subject:<br>
   <input type='text' name='subject' size='20'><br>

   Message:<br>
   <textarea name='content' rows='6' cols='40'></textarea><br>

   <input type='submit' name='send' value='Send'></form></table>";
}




?>

<?
switch($_GET['go']){
case 'delete':
delete();
break;
}

function delete(){
$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE $id=`ID` AND `to_userid`='{$_SESSION['username']}'");

echo "Message Deleted!";

}
?>

 

 

Messages can be SENT and RETRIEVED if they are sent, BUT they cannot be replied to, deleted, and the content of the message won't show up. -.-

 

Help is greatly appreciated. :D

Link to comment
https://forums.phpfreaks.com/topic/166146-switches-and-problems/
Share on other sites

Okay, I'll give the codes again:

 

pm.php

<?php 
session_start(); 
include "db.php";

switch($_GET['sa']){
default:
inbox();
break;

case 'send':
send();
break;

case 'sent':
sent();
break;

case 'msg':
msg();
break;
}

echo"<br />
<a href='pmindex.php'>Inbox</a><br/>
<a href='pmindex.php?action=messages&sa=send'>Compose</a>
<br />";

function inbox(){
print "
<br/><h2>Inbox</h2><table width='100%' class='content'>";

print "<tr><td width='35%'><h3>From</h3></td><td width='55%'><h3>Subject</h3></td><td><h3>Content</h3></td></tr>";

$m=mysql_query("SELECT * FROM messages WHERE `to_userid`='{$_SESSION['username']}'") or die(mysql_error());
while($mail=mysql_fetch_array($m))
{
$from=$mail['from_userid'];
$id=$mail['id'];
$subject=$mail['subject'];

  echo "<tr><td><a href='profile.php?username=$from'>$from</a></td><td><a href='pmindex.php?action=messages&sa=msg&id=$id'>$subject</a></td>";
  echo $_POST['content'];
  echo "<br/><br/><td><a href='pmindex.php?action=messages&go=delete'>Delete</a></td></tr>";
}
echo "</table>";
}



function msg(){
$id=$_GET['id'];
print "<table>";

$ms=mysql_query("SELECT * FROM messages WHERE `to_userid`='{$_SESSION['username']}' AND `id`='$id'") or die(mysql_error());
   

$mamessage=$ms[content];
$msubject=$ms[subject];
$from=$ms[from_userid];

echo "$msubject<br />";

echo "<b>Sent By:</b> <a href='pmindex.php?action=profile&username=$from'>$from</a><br/>
<b>Message:</b><br/>
$mamessage</div><br/>";


print "</table>";

if($_POST['reply']){

   $message=$_POST['content'];

   $subject=$_POST['subject'];
   $to=$_POST['from_userid']; 

      $reply="INSERT INTO messages SET `from_userid`='{$_SESSION['username']}',`to_userid`='$to',`subject`='$subject',`content`='$message',`id`='$id'";

      mysql_query($reply) or die("Could not reply");

   echo'<div class="done">Message Sent!</div><br />';
}

echo "<table><div class='header'>Reply</div><br />";

echo "<form action=\"pmindex.php?action=messages&sa=msg&id=$id\" method=\"post\">

<div class='content'>
   Subject:<br>

   <input type='text' name='subject' size='20' value='Re: $subject'><br>

   Message:<br>

   <textarea name='content' rows='6' cols='40'></textarea><br>

   <input type='submit' name='reply' value='Reply'></form></div></table>";



}



function send(){
if($_POST['send']){

   $to=$_POST['to_userid'];

   $message=$_POST['content'];

   $subject=$_POST['subject'];

   $to=$_POST['to_userid'];

      $send="INSERT INTO messages SET `from_userid`='{$_SESSION['username']}',`to_userid`='$to',`subject`='$subject',`content`='$message'";

      mysql_query($send) or die(mysql_error());

   echo "Message Sent!<br />";
}

print "<table>

<div class='header'>Send</div><br />";

$to=$_GET['to_userid'];

   echo "<form action=\"pmindex.php?action=messages&sa=send\" method=\"post\">

   To:<br>
   <input type='text' name='to_userid' size='20' value='$to'><br/>

   Subject:<br>
   <input type='text' name='subject' size='20'><br>

   Message:<br>
   <textarea name='content' rows='6' cols='40'></textarea><br>

   <input type='submit' name='send' value='Send'></form></table>";
}




?>

<?
switch($_GET['go']){
case 'delete':
delete();
break;
}

function delete(){
$id=$_GET['id'];

mysql_query("DELETE FROM messages WHERE $id=`ID` AND `to_userid`='{$_SESSION['username']}'");

echo "Message Deleted!";

}
?>

 

sendpm.php

<fieldset>
<legend>Send PM</legend>
<form method="post" action="pm.php">

<label for="to">To</label>
<input id="to" type="text" name="to" maxlength="32" value="Send to...">

<br/><br/>
<label for="subject">Subject</label>
<input id="subject" type="text" name="subject" maxlength="50">
<br/><br/>

<label for="content">Body</label><br/>
<textarea id="content" cols="40" rows="6" name="content"></textarea>
<br/><br/>


<input type="submit" name="send" value="Send">
</form></fieldset> 

 

It wont display the content of the messages, won't delete them, and will not let you reply. It just displays the "From", "Suject", and "Content" it says Content but displays the link to delete the message.

I don't exactly understand your problem but I can tell you that

 

switch($_GET['sa']){

 

or any other call to a $_GET variable will not work...when you are not sending variables to it.

 

$_POST will work just fine because you are POSTing it..

 

now if it said this

 

it would work

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.