EPCtech Posted July 30, 2008 Share Posted July 30, 2008 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/ Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 not great at php but.... ill try "SELECT * FROM pmessages WHERE recipient='$name'" echo("<a href='usercp?act=pm&VMSG=in&MSGID=".$row['id']."'>".$row['title']."</a>, from ".$row['sender']."); Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-603928 Share on other sites More sharing options...
Jabop Posted July 30, 2008 Share Posted July 30, 2008 $sql = mysql_query("SELECT * FROM pmessages WHERE recipient='".$name."'") Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-603930 Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 You can include your variable as part of your query without concantination. ("SELECT * FROM pmessages WHERE recipient='$name'") Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-603931 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 wow I got it right I'm learning this stuffz Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-603934 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604048 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 did you include your session? Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604049 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 Yes, of course I did. 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604054 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604057 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 Again, nothing. Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604064 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 echo the name variable Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604065 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 Aha! Good call! Actually, nothing was found! Otherwise, $name="";. Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604066 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604068 Share on other sites More sharing options...
ShaunO Posted July 30, 2008 Share Posted July 30, 2008 Can you show us an example of the table layout of pmessages with an example row? Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604069 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 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 https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-604073 Share on other sites More sharing options...
EPCtech Posted August 1, 2008 Author Share Posted August 1, 2008 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§=msgr&MSGIDr={row['title']}'>Reply to message</a>"; echo "<br />"; } } Then the reply message links to: http://www.en-psyche.com/usercp?act=reply§=msgr&MSGIDr={row[ Best Regards, En-Psyche Management EDIT: Solved. Link to comment https://forums.phpfreaks.com/topic/117412-solved-mysql-syntax-error-in-user-control-panel/#findComment-605254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.