Jump to content

help with PM script!


rille95

Recommended Posts

hi!

 

i am trying to code a personal message script for my website but when i go to the page it says :

"The user you are trying to send a message to doesn't exist! "

 

that's a part of my validation but i want it to validate after i've submitted the data.

 

messages.php:

 

<?php
session_start();
$page="pmessage";
include"header.php";
include"mysql.php";

print"<h1>Personal Messages</h1>";

function make_safe($variable) {
    $variable = mysql_real_escape_string(trim($variable));
    return $variable;
    }
if($_SESSION['loggedin']!=1)
{
print"<center>You must be logged in to send and view personal messages.</center>";
include"side.php";
include"footer.php";
exit;
}
else
{
$title=make_safe($_POST['title']);
$sendto=make_safe($_POST['sendto']);
$message=make_safe($_POST['message']);
$sender_id= $_SESSION['userid'] ;
$title=str_replace(array("<", ">"), array("<", ">"), $title);
$sendto=str_replace(array("<", ">"), array("<", ">"), $sendto);
$message=str_replace(array("<", ">"), array("<", ">"), $message);
$q=mysql_query("SELECT * FROM users WHERE username='{$sendto}'",$c);
if(mysql_num_rows($q))
{
$sendto_id = $q['id'];
}
else if(!mysql_num_rows($q))
{
print"The user you are trying to send a message to doesn't exist!";
include"side.php";
include"footer.php";
exit;
}
else if($sendto_id == $sender_id)
{
print" <center>You can't send a message to yourself.</center>";
include"side.php";
include"footer.php";
exit;
}
else if($title == $message)
{
print" <center>Title and message can't be the same.</center>";
include"side.php";
include"footer.php";
exit;
} 
else if(empty($message))
{
print" <center>Please enter a message</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($title))
{
print" <center>Please enter a title</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($sendto))
{
print" <center>Please enter which user you want to message</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($sendto_id))
{
print" <center>Please enter which user you want to message</center>";
include"side.php";
include"footer.php";
exit;
}
else
{
mysql_query("INSERT INTO pmessage VALUES ('','{$sender_id}','$sendto_id','$title','$message'",$c) or die(mysql_error());
$i=mysql_insert_id($c);
print "<br><br><br><center>Your message has been successfully sent.<br> ";
} 
if (!isset ($_POST['title']) || !isset ($_POST['sendto']) ||!isset ($_POST['message'])) 
{
print"
<p> All fields must be filld out.</p>
<center>
<form action=\"messages.php\" method=\"post\">
<i>Title</i><br><input type=\"text\" name=\"title\"><br>
<i>Send To :</i><br><input type=\"text\" name=\"sendto\"><br>
<i>Message</i><br><textarea name=\"message\" cols=\"20\" rows=\"6\"></textarea><br />
<input type=\"submit\" class=\"button\" value=\"Send Message\"></form><br /></center>";
}
}
include"side.php";
include"footer.php";
?>
    

Link to comment
https://forums.phpfreaks.com/topic/174681-help-with-pm-script/
Share on other sites

okey i figured that one out but now when i press the " send message " button

 

it just prints out the h1 in the beginning and the rest is white.

 

the code for messages.php now :

 

<?php
session_start();
$page="pmessage";
include"header.php";
include"mysql.php";

print"<h1>Personal Messages</h1>";

function make_safe($variable) {
    $variable = mysql_real_escape_string(trim($variable));
    return $variable;
    }
if($_SESSION['loggedin']!=1)
{
print"<center>You must be logged in to send and view personal messages.</center>";
include"side.php";
include"footer.php";
exit;
}
else
{
$title=make_safe($_POST['title']);
$sendto=make_safe($_POST['sendto']);
$message=make_safe($_POST['message']);
$sender_id= $_SESSION['userid'] ;
$title=str_replace(array("<", ">"), array("<", ">"), $title);
$sendto=str_replace(array("<", ">"), array("<", ">"), $sendto);
$message=str_replace(array("<", ">"), array("<", ">"), $message);
$q=mysql_query("SELECT * FROM users WHERE username='{$sendto}'",$c);
if (isset ($_POST['title']) || isset ($_POST['sendto']) || isset ($_POST['message'])) 
{
if(mysql_num_rows($q))
{
$sendto_id = $q['id'];
}
else if(!mysql_num_rows($q))
{
print"The user you are trying to send a message to doesn't exist!";
include"side.php";
include"footer.php";
exit;
}
else if($sendto_id == $sender_id)
{
print" <center>You can't send a message to yourself.</center>";
include"side.php";
include"footer.php";
exit;
}
else if($title == $message)
{
print" <center>Title and message can't be the same.</center>";
include"side.php";
include"footer.php";
exit;
} 
else if(empty($message))
{
print" <center>Please enter a message</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($title))
{
print" <center>Please enter a title</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($sendto))
{
print" <center>Please enter which user you want to message</center>";
include"side.php";
include"footer.php";
exit;
}
else if(empty($sendto_id))
{
print" <center>Please enter which user you want to message</center>";
include"side.php";
include"footer.php";
exit;
}
}
else if (isset ($_POST['title']) || isset ($_POST['sendto']) || isset ($_POST['message']))
{
mysql_query("INSERT INTO pmessage VALUES ('','{$sender_id}','$sendto_id','$title','$message','0');",$c) or die(mysql_error());
print "<br><br><br><center>Your message has been successfully sent.<br> ";
}
else
{
print"
<p> All fields must be filld out.</p>
<center>
<form action=\"messages.php\" method=\"post\">
<i>Title</i><br><input type=\"text\" name=\"title\"><br>
<i>Send To :</i><br><input type=\"text\" name=\"sendto\"><br>
<i>Message</i><br><textarea name=\"message\" cols=\"20\" rows=\"6\"></textarea><br />
<input type=\"submit\" class=\"button\" value=\"Send Message\"></form><br /></center>";
}
}


include"side.php";
include"footer.php";
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/174681-help-with-pm-script/#findComment-920683
Share on other sites

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.