Jump to content

**solved **message system - write.php


pro_se

Recommended Posts

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:
[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>
[/code]

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...
Link to comment
Share on other sites

change this:

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

to:

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

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