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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']}'");

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.