StirCrazy Posted September 6, 2006 Share Posted September 6, 2006 Again sorry my code isn't exactly neat and tidy (still learning) *sorry*.Got a problem that I can't work out ~Trying to allow users of our website to directly email each other without disclosing their email addresses.I'm trying to store all outgoing messages into a mysql database... ....can't work out why none of the data will insert into the table.Any ideas?Below is the relevent data (btw the sql function works fine: the whole site uses it)[code]function contact2() { global $site_prefix; global $site_title; $send_to_user = $_POST['sendto']; $msg = $_POST['msg']; $r = my_query("select username,email from central_users where id='" . mysql_real_escape_string($_SESSION['user']) . "'"); list($username,$from) = mysql_fetch_row($r); $r = my_query("select email from central_users where username='" . mysql_real_escape_string($send_to_user) . "'"); list($to) = mysql_fetch_row($r); $r = my_query("insert into email_reports (site,send_to_user,from,message,email,timedate) values( '" . mysql_real_escape_string($site_prefix) . "', '" . mysql_real_escape_string($send_to_user) . "', '" . mysql_real_escape_string($username) . "', '" . mysql_real_escape_string($msg) . "', '" . mysql_real_escape_string($to) . "', '" . get_time() . "')"); $subject = "New Private Message has arrived from " . $username; $headers = "From: $from\nReply-To: $from\nContent-Type: text/plain\nContent-Transfer-Encoding: 8bit"; $body = stripslashes($msg); @mail($to,$subject,$body,$headers); ?> <br><br> <span class="PlainText">Your message has been sent!</span><br><br> <?php return(0);}[/code][quote]CREATE TABLE `email_reports` ( `id` int(11) unsigned NOT NULL auto_increment, `site` varchar(255) default NULL, `send_to_user` varchar(255) default NULL, `from` varchar(255) default NULL, `message` text, `email` varchar(255) default NULL, `timedate` int(11) NOT NULL default '0', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;[/quote]Thanks for your help guys - dunno what i'd do with you lot.S.C> Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 6, 2006 Share Posted September 6, 2006 Just at a glance, shouldn't you be using mysql_query and not my_query? I searched on php.net and my_query didn't show up Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted September 6, 2006 Author Share Posted September 6, 2006 nah my_query is one of my functions ~ is actually included when this is run (sorry just forgot to add the include just above function contact2() .function my_query($sql) { global $link; $result = @mysql_query($sql, $link); if ($result) return $result; if (DEBUG_MODE) { error_report(10); }; return false;} Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted September 6, 2006 Author Share Posted September 6, 2006 I'm guessing that the error lies here:-[code] $r = my_query("insert into email_reports (site,send_to_user,from,message,email,timedate) values( '" . mysql_real_escape_string($site_prefix) . "', '" . mysql_real_escape_string($send_to_user) . "', '" . mysql_real_escape_string($username) . "', '" . mysql_real_escape_string($msg) . "', '" . mysql_real_escape_string($to) . "', '" . get_time() . "')"); [/code]and not in the way the database table is set up?S.C> Quote Link to comment Share on other sites More sharing options...
.josh Posted September 6, 2006 Share Posted September 6, 2006 instead of this:[code]$r = my_query("insert into email_reports (site,send_to_user,from,message,email,timedate) values( '" . mysql_real_escape_string($site_prefix) . "', '" . mysql_real_escape_string($send_to_user) . "', '" . mysql_real_escape_string($username) . "', '" . mysql_real_escape_string($msg) . "', '" . mysql_real_escape_string($to) . "', '" . get_time() . "')");[/code]do this:[code]$sql = "insert into email_reports (site,send_to_user,from,message,email,timedate) values( '" . mysql_real_escape_string($site_prefix) . "', '" . mysql_real_escape_string($send_to_user) . "', '" . mysql_real_escape_string($username) . "', '" . mysql_real_escape_string($msg) . "', '" . mysql_real_escape_string($to) . "', '" . get_time() . "')";$r = my_query($sql);[/code]now, echo $sql and examine it. insert it directly into your db through phpmyadmin or whatever. see if it works there. If it does, then the problem is your code, not the query. post what you find out, including the query string. Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted September 6, 2006 Author Share Posted September 6, 2006 GENIUS # Thanks Crayon Violent: was because I used FROM!!! DOH!Thanks for the nudge in the right directionS.C>ErrorSQL query: INSERT INTO email_reports( site, send_to_user, [b][color=red]FROM[/color][/b] , message, email, timedate ) VALUES ('site1', 'sendto-user', 'stircrazy', 'Hiya,\r\n\r\nPut your message here...\r\n\r\nRegards,\r\n\r\n', 'user@domain.com', '1157586163') MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from,message,email,timedate) values( 'site1', 'sendto-user', 'stircrazy', 'Hiya,\r\n\r\nP' at line 1 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.