aebstract Posted June 16, 2006 Share Posted June 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12172-pm-box/ Share on other sites More sharing options...
.josh Posted June 16, 2006 Share Posted June 16, 2006 your either missing some quotes if compose is supposed to be a value or a $ if it's supposed to be another variableif ($action == 'compose') {orif ($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=composethen you would do like:$action=$_GET['action'];if ($action == 'compose') {..} Quote Link to comment https://forums.phpfreaks.com/topic/12172-pm-box/#findComment-46348 Share on other sites More sharing options...
aebstract Posted June 16, 2006 Author Share Posted June 16, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Everything is working fine, except it won't put the information in.[/quote]^^ Quote Link to comment https://forums.phpfreaks.com/topic/12172-pm-box/#findComment-46365 Share on other sites More sharing options...
aebstract Posted June 17, 2006 Author Share Posted June 17, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/12172-pm-box/#findComment-46542 Share on other sites More sharing options...
AndyB Posted June 17, 2006 Share Posted June 17, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/12172-pm-box/#findComment-46565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.