/    Sign up×
Community /Pin to ProfileBookmark

Private Messaging System Errors

Hi there i have attempted to make my own Private messaging system but for some reason i gain some errors

1st is displaying the private messages for the user who is logged in but doesnt do that this is what i get back along with the query

SELECT * FROM pms WHERE to=”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 ‘to=”’ at line 1

Now the code is for this one is

[code=php]
$uQuery=”SELECT * FROM pms WHERE to='”.$_SESSION[‘user’].”‘”;
echo “<font color=”#FFFFFF”>”;
echo $uQuery;
echo “</font>”;
$rs=mysqli_query($con,$uQuery);
if(!$rs)
{
echo “Error:”.mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
while($data=$rs->fetch_assoc())
{
echo “<tr><td width=”20″><font color=”#FFFFFF”>”.$data[‘from’].”</font></td>”;
echo “<td><font color=”#FFFFFF”>”.$data[‘to’].”</font></a>”;
echo “<td><font color=”#FFFFFF”><a href=”showmessage.php?mid=”.$data[‘mid’].””>
“.$data[‘subject’].”</a></font></td>”;
echo “<td>”;
if($data[‘read’]==0)
{
echo “<img src=”images/pm_new.gif” alt=”New Message” />”;
}
else
{
echo “<img src=”images/pm_old.gif” alt=”old Message” />”;
}
echo “</td></tr>”;
}
}
}
[/code]

The Other one is

Showmessage which is for message content which when only page i want it to change from new message to old message this is what i get back from echoing the query back

update pms SET read=’1′ WHERE mid=”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 ‘read=’1′ WHERE mid=”’ at line 1

And this is the Code i have.

[Code]
<?php
session_start();
$gQuery=”SELECT * FROM pms where mid=’$mid'”;
//excute the query
//echo $gQuery;
$rs=mysqli_query($con,$gQuery);
if(!$rs)
{
$dbError=”Error:Failed to executing query”
.mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$to=$data[‘to’];
$from=$data[‘from’];
$subject=$data[‘subject’];
$content=$data[‘content’];
$mid=$data[‘mid’];
$read=$data[‘read’];
}
}
?>
<form method=”post” action=””>
<input name=”read” type=”hidden” value=”<? echo $read; ?>” />
<input name=”mid” type=”hidden” value=”<? echo $mid; ?>” />
</form>
<?php
error_reporting(e_all);
echo “<font color=”#FFFFFF”>”;
echo $mid;
echo “</font>”;
$rQuery=”update pms SET read=’1′ WHERE mid=’$mid'”;
echo “<font color=”#FFFFFF”>”;
echo $rQuery;
echo “</font>”;
$rs=mysqli_query($con,$rQuery);
if(!$rs)
{
echo “Error:”.mysqli_error($con);
}
else
{
?><div align=”center”>
<table width=”390″ border=”1″>
<tr>
<td colspan=”7″ align=”center”><font color=”#FFFFFF”>Messages</font></td></tr>
</font>
<?php
include(“dbconnect.php”);
$uQuery=”SELECT * FROM pms where username='”.$_SESSION[‘user’].”‘”;
$rs=mysqli_query($con,$uQuery);
if(!$rs)
{
echo “Error:”.mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
while($data=$rs->fetch_assoc())
{
echo “<tr><td width=”20″><font color=”#FFFFFF”>From:</font></td><td><font color=”#FFFFFF”>”.$data[‘from’].”</font></td></tr>”;
echo “<tr><td><font color=”#FFFFFF”>To:</font></td><td><font color=”#FFFFFF”>”.$data[‘to’].”</font></td></tr>”;
echo “<tr><td><font color=”#FFFFFF”>Content:</font></font></td><td><font color=”#FFFFFF”>”.$data[‘content’].”</font></td></tr>”;
}
}
}
echo “<tr>
<td><font color=”#FFFFFF”><a href=”replypm.php?mid=”;
echo $_GET[‘mid’]; ?><?php echo””>Reply</a></font></td></tr>”;
?>
</table></div><?php
}
?>
[/code]

How can i go about fixing these can anyone help me please i do not know why its doing this anything that i am doing wrong?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 05.2006 — "To" is a reserved word in MySQL, so you must back-quote it when using it as a column or table identifier:
<i>
</i><span><code>to</code></span>
Copy linkTweet thisAlerts:
@william232authorDec 05.2006 — So the query goes like this?

$uQuery="SELECT * FROM pms WHERE to ='".$_SESSION['user']."'";

wud that be correct?
Copy linkTweet thisAlerts:
@NogDogDec 05.2006 — Assuming there's nothing else wrong, that should solve the problem.
×

Success!

Help @william232 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...