reply.php form not inserting
hello,
was wondering if you can help me please as my code below is not inserting the stuff in to the database?.
PHP Code:
<?php $title = "MBAPPZ.com - Reply"; ?>
<?php require("styles/top.php"); ?>
<div id='full'>
<?php
if($username){
echo "<b>Reply To Message</b><br /><br />";
if ($_POST['replybutton']){
$subject = $_POST['replysubject'];
$content = $_POST['replycontent'];
$replyid = $_POST['replyid'];
if ($subject && $content){
require('scripts/connect.php');
$date = date("F d, Y");
$query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'");
$numrows = mysql_num_rows($query);
if ($numrows == 0){
$query = mysql_query("SELECT * FROM messages WHERE id='$replyid' AND to_user='$username'");
$numrows = mysql_num_rows($query);
if ($numrows == 1){
$row = mysql_fetch_assoc($query);
$to_id = $row['from_id'];
$to_user = $row['from_user'];
mysql_query("INSERT INTO messages VALUES('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')");
echo "Your reply has been sent thank you. <a href='inbox.php'>Click Here</a> to return to your inbox.";
}
else
echo "No message was sent. An error has occured!!!.";
}
else
echo "You can NOT resend the same messages.";
}
else
echo "You did not supply a subject and / or content.";
}
else
echo "You must submit a response to a message.";
}
else
echo "You must be logged in to view this page sorry.";
?>
</div>
<?php require("styles/bottom.php"); ?>
Re: reply.php form not inserting
I don't see any glaring errors. What error are you getting, if any?
Have you tried debugging? Try echoing out after all of your if statements to see where it is getting caught.
Also, your entire script is full of possible SQL injection. You should look at using parameterized queries to remove the risk. I usually use PDO for my parameterized queries in PHP.
Re: reply.php form not inserting
I was also ment to say that it says its been added to database but the data isn't in the database?
PHP Code:
<?php $title = "MBAPPZ.com - Viewing Private Message"; ?>
<?php require("styles/top.php"); ?>
<div id='full'>
<?php
if($username){
$msg_id = $_GET['id'];
require('scripts/connect.php');
$query = mysql_query("SELECT * FROM messages WHERE id=$msg_id");
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while($row = mysql_fetch_assoc($query)){
$msg_id = $row['id'];
$msg_to_user = $row['to_user'];
$msg_to_id = $row['to_id'];
$msg_from_user = $row['from_user'];
$msg_from_id = $row['from_id'];
$msg_subject = $row['subject'];
$msg_content = nl2br($row['content']);
$msg_date = $row['date'];
echo "<div id='profile'>
<div id='leftside'>
Some Information Goes Here
</div>
<div id='rightside'>
<div>
<b class='corners'>
<b class='corners1'><b></b></b>
<b class='corners2'><b></b></b>
<b class='corners3'></b>
<b class='corners4'></b>
<b class='corners5'></b></b>
<div class='cornersfg'>
<div class='top'>$msg_subject</div>
</div>
<div class='bottom'>
<table cellpadding='5px' cellspacing='5px'>
<tr>
<td><b>Date Sent:</b></td>
<td>$msg_date</td>
</tr>
<tr>
<td><b>Sent From:</b></td>
<td><a href='profile.php?id=$msg_from_id'>$msg_from_user</a></td>
</tr>
<tr>
<td><b>Sent To:</b></td>
<td><a href='profile.php?id=$msg_to_id'>$msg_to_user</a></td>
</table>
<hr>
<table cellpadding='5px' cellspacing='5px'>
<tr>
<td><b>Message:</b</td>
<td>$msg_content</td>
</tr>
</table>";
echo "</div>
<b class='corners'>
<b class='corners5'></b>
<b class='corners4'></b>
<b class='corners3'></b>
<b class='corners2'><b></b></b>
<b class='corners1'><b></b></b></b>
</div>";
echo"<a name='comments'></a><div style='margin-top: 15px;'>
<b class='corners'>
<b class='corners1'><b></b></b>
<b class='corners2'><b></b></b>
<b class='corners3'></b>
<b class='corners4'></b>
<b class='corners5'></b></b>
<div class='cornersfg'>
<div class='top'>Send A Reply To $msg_from_user's Message</div>
</div>
<div class='bottom'>
<form action='reply.php' method='POST'>
<input type='hidden' value='$msg_id' name='replyid'>
<input text='text' name='replysubject' value='RE: $msg_subject'><br />
<textarea name='replycontent' style='width: 400px; height: 75px;'></textarea><br /><br />
<input type='submit' name='replybutton' value='Send Reply' class='button'>
</form>
";
echo "</div></div>
<b class='corners'>
<b class='corners5'></b>
<b class='corners4'></b>
<b class='corners3'></b>
<b class='corners2'><b></b></b>
<b class='corners1'><b></b></b></b>
</div>";
// end comments stuff
echo "</div>";
}
}
else
echo "There has been an error please try again.";
}
else
echo "You must be logged in to view this page sorry.";
?>
</div>
<?php require("styles/bottom.php"); ?>
Re: reply.php form not inserting
of course it will show the message because you are not checking if the query had an error or not you may want to do this
first we add an if to your query and second we put mysql_error(); in case there was an error so it will tell you why
PHP Code:
$query = "INSERT INTO messages VALUES('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')";
if($query_run = mysql_query($query) {
echo "Your reply has been sent thank you. <a href='inbox.php'>Click Here</a> to return to your inbox.";
}
else
echo "No message was sent. An error has occured!!!.";
echo mysql_error();
}
what i just did i make sure that the query run throw otherwise it would show you the message that cause the error
now you will understand why you dont have any data in database!
GoodLuck:wave: