Jump to content

PHP/MySQL error - PMsys


bam2550

Recommended Posts

<?php
include("include/session.php");

$to = trim(mysql_real_escape_string($_POST["sendto"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
if ((isset($to) && isset($sub) && isset($msg)) && (!empty($to) && !empty($sub) && !empty($msg))

// This is Line 10 // $con = mysql_connect("localhost","iii","iii");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);

mysql_query("INSERT INTO private_messages (sendto, from, subject, message) 
VALUES ('$to', '$from', '$sub', '$msg')") or die(mysql_error());

mysql_close($con);
}

else {
echo "Please fill out the form" }

?>

<?php
include("include/session.php");

$to = trim(mysql_real_escape_string($_POST["sendto"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
if (isset($to)||isset($sub)||isset($msg)||!empty($to)||!empty($sub)||!empty($msg)){

$con = mysql_connect("localhost","1","1");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);

mysql_query("INSERT INTO private_messages (sendto, from, subject, message) 
VALUES ('$to', '$from', '$sub', '$msg')") or die(mysql_error());

mysql_close($con);
}

else {
echo "Please fill out the form" }

?>

using that exact code i received this error...

 

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, subject, message) VALUES ('', 'admin', 'fe', 'fe')' at line 1

 

do i have to use ´ or ` or ' ??

<?php
include("include/session.php");

$to = trim(mysql_real_escape_string($_POST["sendto"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
if (isset($to)||isset($sub)||isset($msg)||!empty($to)||!empty($sub)||!empty($msg)){

$con = mysql_connect("localhost","1","1");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);

mysql_query("INSERT INTO private_messages ('sendto', 'from', 'subject', 'message') 
VALUES ('$to', '$from', '$sub', '$msg')") or die(mysql_error());

mysql_close($con);
}

else {
echo "Please fill out the form" }

?>

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 ''sendto', 'from', 'subject', 'message') VALUES ('', 'admin', 'r', 'r')' at line 1

 

is it not reading the from? it doesnt look like it is...

 

seeing as from is blank in this error message, but it is aparent in the boxes...

 

=== I think i found why... ====

The onlything that was changed to sendto was the tables in MySQL...

Okay well i found the error was i didnt wrap the things in single quotes... i did and got a totally new error!

My new error is:

 

Unknown column 'mod123' in 'field list'

 

PS mod123 is my to feild, atleast it should be!

 

<?php
include("include/session.php");

$to = trim(mysql_real_escape_string($_POST["to"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
if (isset($to)||isset($sub)||isset($msg)||!empty($to)||!empty($sub)||!empty($msg)){

$con = mysql_connect("localhost","r","l");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);

mysql_query("INSERT INTO private_messages (`sendto`,`from`,`subject`,`message`) 
VALUES (`$to`,`$from`,`$sub`,`$msg`)") or die(mysql_error());;

mysql_close($con);
}

else {
echo "Please fill out the form"; }

?>

If your getting

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 '`testing`,``,``)' at line 2

 

Try:

<?php
include("include/session.php");

$to = trim(mysql_real_escape_string($_POST["sendto"]));
$from = $username;
$sub = trim(mysql_real_escape_string($_POST["sub"]));
$msg = trim(mysql_real_escape_string($_POST["msg"]));
if (isset($to)||isset($sub)||isset($msg)||!empty($to)||!empty($sub)||!empty($msg)){

$con = mysql_connect("localhost","r","l");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);

mysql_query("INSERT INTO `private_messages` (`sendto`, `from`, `subject`, `message`) 
VALUES ('" . $sendto . "', '" . $from . "', '" . $sub . "', '" . $msg . "')") or die(mysql_error());

mysql_close($con);
}

else {
echo "Please fill out the form"; }

?>

 

 

Okay... Yeah. Now my only problem is retreiving it in inbox.php. It is probably a similar problem to send.php ...

 

If anyone would like to assist me...

 

[code=php:0]<?php
include("include/session.php");
?>
<?php
$con = mysql_connect("localhost","~","~");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("messaging", $con);
$result = mysql_query("SELECT * FROM private_messages WHERE 'sendto'='$username'", $con);

if (!$result) {
    die( "Error, MySQL Said: " . mysql_error() );
}

while($row = mysql_fetch_array($result))
  {
  echo $row['from'] . " " . $row['message'];
  echo "<br />";
  echo $row['sendto'] . " " . $row['subject'];
  }

mysql_close($con);
?>[/php

 

The way it is output is pretty  crudy, but even if it is messy, idc. I just want to get it outputted (is that even a word??)

This line:

 

$result = mysql_query("SELECT * FROM private_messages WHERE 'sendto'='$username'", $con);

 

Should be:

 

$result = mysql_query("SELECT * FROM private_messages WHERE sendto='$username'", $con);

 

Weather or not that is the problem, i dont know - i've not read the whole thread, just saw the error. I assume $username is defined in session.php?

Archived

This topic is now archived and is closed to further replies.

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