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" }

?>

Link to comment
Share on other sites

<?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" }

?>

Link to comment
Share on other sites

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 ' ??

Link to comment
Share on other sites

<?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" }

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

hmm

Link to comment
Share on other sites

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"; }

?>

Link to comment
Share on other sites

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"; }

?>

 

 

Link to comment
Share on other sites

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??)

Link to comment
Share on other sites

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?

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.