Jump to content

pm box


aebstract

Recommended Posts

Hi, I am trying to get my pm send form to insert the data from the form in to the database so that whoever is recieving the pm can view it. Everything is working fine, except it won't put the information in. Can anyone help me with this? The problem is in the if (action == compose) { section of the script, and here the script is:


[code]<?php  
session_start();
header("Cache-control: private");  
if(!isset($_SESSION["id"]))  
{  
header("Location: index.php?menu=mustlogin");  
}



if($action == compose){
$content .= '<div id="pmbox">';


if (isset ($_POST['submit'])) {
$problem = FALSE;  
$_POST['reciever'] = strip_tags($_POST['reciever']);
$_POST['subject'] = strip_tags($_POST['subject']);
$_POST['message'] = strip_tags($_POST['message']);  

if (empty ($_POST['reciever'])) {
$problem = TRUE; $content .= 'Reciever is a required field<br />';
}  

if (empty ($_POST['subject'])) {
$problem = TRUE;
$content .= 'Subject is a required field<br />';
}  

if (empty ($_POST['message'])) {
$problem = TRUE;
$content .= 'Message is a required field<br />';
}  

$query = mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['reciever']."'");
$query = mysql_fetch_array($query);         
if ($query){     
$recieverid = $query['id'];                  

} else {         

$problem = TRUE;         
$content .= 'Invalid Username<br />';

}  
if (!$problem) {  
$reciever = $_POST['reciever'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$datesent = date('F j, Y - g:i a');  
$result = MYSQL_QUERY("INSERT INTO pmbox (recieverid,sender,senderid,message,subject,datesent,read)". "VALUES ('$recieverid', '$username', '$id', '$message', '$subject', '$datesent', '0')");  
include "connect.php";    
header ("Location: index.php?menu=pmbox&action=pmsent");  
} else {
$content .= '<br />';
}
}    
$content .= '
  
<form action="index.php?menu=pmbox&action=compose" method="post">  
Reciever: <br />
<input type="text" maxlength="14" class="textfield" name="reciever" size="20" value="' . $_POST['reciever'] . '" />
<br />
Subject: <br />
<input type="text" class="textfield" name="subject" maxlength="15" size="20" value="' . $_POST['subject'] . '" />
<br />
Message: <br /><textarea class="textfield" name="message" rows="10" cols="40" value="' . $_POST['message'] . '"></textarea>
<br /><br />  
<input type="submit" name="submit" value="Send PM" class="textfield" />
</form>  

';



$content .= '</div>';
} elseif ($action == sentmail){

$content .= '
<div id="pmbox">
sent mail
</div>
';




} else {
$content .= '<div id="pmbox">
<table><tr id="trone"><td id="tdone">From:</td><td id="tdtwo">Subject:</td><td id="tdthree">Date:</td></tr>

';

$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id'");    
while($r=mysql_fetch_array($result))  {  
$sender=$r["sender"];  
$senderid=$r["senderid"];  
$message=$r["message"];  
$subject=$r["subject"];
$datesent=$r["datesent"];
$pmid=$r["pmid"];  
$content .= "

<tr id=trtwo><td id=tdone><a href=index.php?menu=profileview&user=$senderid>$sender</a></td><td id=tdtwo><a href=index.php?menu=pmbox&action=read&read=$pmid>$subject</a></td><td id=tdthree>$datesent</td></tr>


";
}

$content .= "</table></div>";
}



?>[/code]


thanks
Link to comment
Share on other sites

your either missing some quotes if compose is supposed to be a value or a $ if it's supposed to be another variable

if ($action == 'compose') {

or

if ($action == $compose) {

but also, i don't see where you've even set $action to compare it to anything... i'm gonna take a guess and say that $action is being passed in the url from a link, like blah.php?action=blah

?

you need to do like

$action = $_GET['action'];

if you want to use $action in that way. so if you were shooting for having a link like

blah.php?action=compose

then you would do like:

$action=$_GET['action'];
if ($action == 'compose') {
.
.
}
Link to comment
Share on other sites

Okay so the code section that is having the problem is here:

[code]
if($action == compose){
$content .= '<div id="pmbox">';


if (isset ($_POST['submit'])) {
$problem = FALSE;  
$_POST['reciever'] = strip_tags($_POST['reciever']);
$_POST['subject'] = strip_tags($_POST['subject']);
$_POST['message'] = strip_tags($_POST['message']);  

if (empty ($_POST['reciever'])) {
$problem = TRUE; $content .= 'Reciever is a required field<br />';
}  

if (empty ($_POST['subject'])) {
$problem = TRUE;
$content .= 'Subject is a required field<br />';
}  

if (empty ($_POST['message'])) {
$problem = TRUE;
$content .= 'Message is a required field<br />';
}  

$query = mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['reciever']."'");
$query = mysql_fetch_array($query);         
if ($query){     
$recieverid = $query['id'];                  

} else {         

$problem = TRUE;         
$content .= 'Invalid Username<br />';

}  
if (!$problem) {  
$reciever = $_POST['reciever'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$datesent = date('F j, Y - g:i a');  

$insert = mysql_query("INSERT INTO pmbox (recieverid,sender,senderid,message,subject,datesent,read)".
"VALUES ('$recieverid', '$username', '$id', '$message', '$subject', '$datesent', '0')");


header ("Location: index.php?menu=pmbox&action=pmsent");  
} else {
$content .= '<br />';
}
}    
$content .= '
  
<form action="index.php?menu=pmbox&action=compose" method="post">  
Reciever: <br />
<input type="text" maxlength="14" class="textfield" name="reciever" size="20" value="' . $_POST['reciever'] . '" />
<br />
Subject: <br />
<input type="text" class="textfield" name="subject" maxlength="15" size="20" value="' . $_POST['subject'] . '" />
<br />
Message: <br /><textarea class="textfield" name="message" rows="10" cols="40" value="' . $_POST['message'] . '"></textarea>
<br /><br />  
<input type="submit" name="submit" value="Send PM" class="textfield" />
</form>  

';



$content .= '</div>';
[/code]


Like I said, I know the url/variable stuff is working, cause it works on the other parts that are just like this. The problem is the information actually getting placed in to the database. If theres some kind of code I can put in to test for the error, please shoot it at me and explain and I will give it a shot, if you can see the problem.. that helps too! :P Thanks!
Link to comment
Share on other sites

[b]read[/b] is a reserved word in MySQL so you cannot use it as a fieldname in a database table. The solution is either to rename it (best), or use backticks on it `read`.

If your query action had included error trapping, you would have spotted this immediately.

[a href=\"http://www.htmlite.com/mysql002a.php\" target=\"_blank\"]http://www.htmlite.com/mysql002a.php[/a] is a nice list of MySQL reserved words that is worth book-marking.
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.