pro_se Posted August 24, 2006 Share Posted August 24, 2006 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]<?phprequire '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... Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 24, 2006 Share Posted August 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
pro_se Posted August 24, 2006 Author Share Posted August 24, 2006 Warning: mysql_result() [function.mysql-result]: toid not found in MySQL result index 25 in /var/www/write.php on line 142they are not being output... but everything else is getting put it... Quote Link to comment Share on other sites More sharing options...
pro_se Posted August 24, 2006 Author Share Posted August 24, 2006 waaaaiiittt!!! i got it.... the error explains it all... Quote Link to comment 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.