Jump to content


Photo

**solved **message system - write.php


  • Please log in to reply
3 replies to this topic

#1 pro_se

pro_se
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 24 August 2006 - 08:28 PM

i am trying to create a messaging system but i am running into some problems... here is the table format: CREATE TABLE `messages` (
  `msgid` mediumint(9) NOT NULL auto_increment,
  `toname` varchar(255) NOT NULL default '',
  `toid` varchar(255) NOT NULL default '',
  `fromid` varchar(255) NOT NULL default '',
  `date` varchar(255) NOT NULL default '',
  `time` varchar(255) NOT NULL default '',
  `subject` varchar(255) NOT NULL default '',
  `message` text NOT NULL,
  `status` varchar(255) NOT NULL default 'msg',
  `fromname` varchar(255) NOT NULL default '',
  `read` varchar(255) NOT NULL default '** New **',
  PRIMARY KEY  (`msgid`)
)


and here is the php code:
<?php
require 'db_connect.php'; 
if (isset($_POST['submit'])) { // if form has been submitted
	/* check they filled in what they supposed to, 
	passwords matched, username
	isn't already taken, etc. */
	$fromname = $_SESSION['username'];
	$result4 = mysql_query("SELECT * FROM users WHERE username='$fromname'");
while($r4=mysql_fetch_array($result4))
{	
   $toid=$r4["toid"];
}
	$date = date('m d, Y');
	$time = date('h:i A');
	$name = "$fname $lname";
	$ip = getenv("REMOTE_ADDR");
	$id = $_GET['id'];
	
	$insert = "INSERT INTO messages (
			toname, 
			toid, 
			fromid,
			date, 
			time, 
			subject,
			message,
			status,
			fromname) 
			VALUES (
			'".$_POST['to']."',
			'$toid',
			'$fromid',
			'$date',
			'$time',
			'".$_POST['subject']."',
			'".$_POST['message']."',
			'msg',
			'$fromname')";

	$add_member = $db_object->query($insert);

	if (DB::isError($add_member)) {
		die($add_member->getMessage());
	}

	$db_object->disconnect();
?>
       Message Sent, Thanks. <?php

} else {	// if form hasn't been submitted

?>
<form name="form1" method="post" action="">
          TO:
          <input name="to" type="text" id="to" value="<?php
$msgid = $_GET['msgid'];
$result = mysql_query("SELECT * FROM messages WHERE msgid='$msgid'");
while($r=mysql_fetch_array($result))
{	
   $fromname=$r["fromname"];
   
echo "$fromname";
}
?>">
          <br><br>
                FROM:
        <strong><input name="from" type="text" disabled="disabled" id="from" value="<?php

$from = $_SESSION['username'];
$result = mysql_query("SELECT * FROM users WHERE username='$from'");
while($r=mysql_fetch_array($result))
{	
   $username=$r["username"];
   
echo "$username";
}
?>"><br><br>
        </strong>SUBJECT: 
                <input name="subject" type="text" value="<?php
$msgid = $_GET['msgid'];
$result = mysql_query("SELECT * FROM messages WHERE msgid='$msgid'");
while($r=mysql_fetch_array($result))
{	
   $subject=$r["subject"];
   
echo "$subject";
}
?>" id="subject">
                <br>
                <br>
                MESSAGE: 
        <div align="left">
                  <textarea name="message" cols="69" rows="6" id="message"><?php
$msgid = $_GET['msgid'];
$result = mysql_query("SELECT * FROM messages WHERE msgid='$msgid'");
while($r=mysql_fetch_array($result))
{	
   $message=$r["message"];
   $date=$r["date"];
   $time=$r["time"];
   
echo "



---- ORIGINAL MESSAGE: ----
$message";
}
?></textarea>
                  <br>
                  <BR>
                  <input name="submit" type="submit" id="submit" value="Submit">
        <strong><a href="messagecenter.php">CANCEL</a></strong></div>
        </form><?php

}

?>
		</span>
		
		<span class=style2>		</span>

now, when i try to send a message it does not put the toid and fromid... i would really like to know how to insert that into the database... everything else inserts fine... but not the toid and fromid... i need to get that out of a different table called users...

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 08:31 PM

change this:

$result4 = mysql_query("SELECT * FROM users WHERE username='$fromname'");
while($r4=mysql_fetch_array($result4))
{	
   $toid=$r4["toid"];
}

to:

$result4 = mysql_query("SELECT * FROM users WHERE username='$fromname'") or die(mysql_error());
   $toid = mysql_result($result4, 0, "toid");

See if you are getting an error on your toid query.  Also, echo out your $insert query to see what it looks like...see if the vars are being input or not.

#3 pro_se

pro_se
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 24 August 2006 - 08:34 PM

Warning: mysql_result() [function.mysql-result]: toid not found in MySQL result index 25 in /var/www/write.php on line 142

they are not being output... but everything else is getting put it...

#4 pro_se

pro_se
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 24 August 2006 - 08:40 PM

waaaaiiittt!!! i got it.... the error explains it all...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users