Jump to content

[SOLVED] MySQL Syntax Error in User Control Panel


EPCtech

Recommended Posts

Hi,

I have the following code:

$sql = mysql_query("SELECT * FROM pmessages WHERE recipient=" . $name) or die("Sorry, there was an error: ".mysql_error());
 		while($row=mysql_fetch_array($sql))
 					{
					echo("<a href='usercp?act=pm&VMSG=in&MSGID=".$row['id']."'>".$row['title']."</a>, from ".$row['sender']);
					}

It's supposed to show all personal messages for the user, but instead it shows the error:

 

Sorry, there was an 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 '' at line 1

 

I don't know what to do. Could someone help?

 

Best Regards,

En-Psyche Management

My username at the website is "En-Psyche". There are two messages where the recipient is "En-Psyche". The system is supposed to detect that, then show the messages in a list in my user control panel. (For a demonstration of how it works, go to www.en-psyche.com, register, login, and go to your private messages. I'll send you a message, but you wont get it.)

 

In other words, that technique never worked....Got any other suggestions please? (Thanks for trying :))

 

Best Regards,

En-Psyche Management

Yes, of course I did. :D

 

Best Regards,

En-Psyche Management

 

EDIT: Noticing there might be something wrong with this, here is the code that made the variable $name.

 

$nasql=mysql_query("SELECT username FROM login WHERE id=".$_SESSION['user_id']);
list($name)=mysql_fetch_array($nasql);

try dis

<?php
session_start();
$query  = "SELECT * FROM pmessages WHERE recipient='$name'" or die("Sorry, there was an error: ".mysql_error());
$result = mysql_query($query);
?>

<?php
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  {
echo "<a href='usercp?act=pm&VMSG=in&MSGID={$row['name']}'>{$row['title']}</a>, from {$row['name']}";
}
?>

 

 

EDIT:

___________________________________________

for your session name code use:

 

$nasql=mysql_query("SELECT username FROM login WHERE id='{$_SESSION['user_id']}'");

replace the $name in the pmessages.php page or w/e straight up with this

<?php
session_start();
$query  = "SELECT * FROM pmessages WHERE recipient='{$_SESSION['user_id']}'" or die("Sorry, there was an error: ".mysql_error());
$result = mysql_query($query);
?>

Right before you two posted your messages, I found the problem! In the place where it was all echoed, the server checked to make sure they were logged in. Instead of cluttering all that with the code, I put all the code into the function "get_body();". I put the name variable OUTSIDE the function. Which means that $name doesn't exist in the function. Which means, I need to put the $name part of the code into the function brackets. :)

 

Long story short, it's finished! Thanks guys, you were a big help! In fact, if you want, I could put your guys' name on En-Psyche to show EP's gratitude. :)

 

Best Regards,

En-Psyche Management

It's not working when I try to insert it twice.

	 		{
 		echo("Showing personal messages:<br />");
		$query  = "SELECT * FROM pmessages WHERE recipient='$name'" or die("Sorry, there was an error: ".mysql_error());
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  				{
				echo "<a href='usercp?act=pm&VMSG=in&MSGID={$row['id']}'>{$row['title']}</a>, from {$row['sender']} :: <a href='usercp?act=reply&sect=msgr&MSGIDr={row['title']}'>Reply to message</a>";
				echo "<br />";
				}
		}

 

Then the reply message links to:

http://www.en-psyche.com/usercp?act=reply&sect=msgr&MSGIDr={row[

 

Best Regards,

En-Psyche Management

 

EDIT: Solved.

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.