Page 1 of 1

comparision of posted data with table and inserting new data

Posted: Fri Feb 12, 2010 1:33 pm
by kristijan
First of all HI,
I am new to this forum and I hope that i'll finally find some answers here.

I am doing simple PM system on my website and I'm stuck on one part of the code. I am currently making "send message" part of pm system which should be simple but i can't figure out where i went wrong so here is the code to which form is submitted.
After posting form i get blank page without any error or result. I dunno what's wrong :\

Code: Select all

 
<?php 
include 'mysql/config.php'; 
$subject = $_POST['subject']; 
$touser = $_POST['touser']; 
$body = $_POST['body']; 
$fromuser = $_POST['fromuser']; 
 
$receiver = mysql_query("SELECT username FROM userlist WHERE username = '".$touser."'") or die('Nije mogu?e prona?i ovog korisnika'); 
    $checkrec = mysql_num_rows($receiver); 
   
    if(($checkrec) == 0) { 
        echo "Korisnik kojemu pokušavate poslati poruku ne postoji. <br /><br /> 
            <form action='index.php?page=mojprofil&subpage=newmessage' method='post'> 
            <input type='submit' value='Pokušajte ponovno' class='submit' />   
            </form>"; 
            exit; 
      } 
      elseif(strlen($body)) < 1){ 
      echo "Nije mogu?e poslati praznu poruku. <br /><br /> 
          <form action='index.php?page=mojprofil&subpage=newmessage' method='post'> 
          <input type='submit' value='Pokušajte ponovno' class='submit' />   
          </form>"; 
          exit; 
      } 
      elseif(strlen($subject)) < 1){ 
       echo "Nije mogu?e poslati poruku bez Naslova. <br /><br /> 
          <form action='index.php?page=mojprofil&subpage=newmessage' method='post'> 
          <input type='submit' value='Pokušajte ponovno' class='submit' />   
          </form>"; 
          exit; 
      } 
      else{ 
      $insert = mysql_query("INSERT INTO pm_inbox SET from_user = '".$fromuser."', to_user = '".$touser."', subject = '".$subject."', body = '".$body."'") OR die("Nije mogu?e poslati poruku: <br />" .mysql_error()); 
        if($insert){ echo 'Poruka uspješno poslana';} 
        if(!$insert) { echo 'Poruka nije poslana. ';}        
      } 
     
?>
 

Re: comparision of posted data with table and inserting new data

Posted: Sun Feb 14, 2010 8:58 pm
by jkraft10
You have two extra ")" after the strlen. Remove them and you should be fine.

<?php
include 'mysql/config.php';
$subject = $_POST['subject'];
$touser = $_POST['touser'];
$body = $_POST['body'];
$fromuser = $_POST['fromuser'];

$receiver = mysql_query("SELECT username FROM userlist WHERE username = '".$touser."'") or die('Nije moguće pronaći ovog korisnika');
$checkrec = mysql_num_rows($receiver);

if(($checkrec) == 0) {
echo "Korisnik kojemu pokušavate poslati poruku ne postoji. <br /><br />
<form action='index.php?page=mojprofil&subpage=newmessage' method='post'>
<input type='submit' value='Pokušajte ponovno' class='submit' />
</form>";
exit;
}
elseif(strlen($body)) < 1){ //it should look like this: elseif(strlen($body) < 1){
echo "Nije moguće poslati praznu poruku. <br /><br />
<form action='index.php?page=mojprofil&subpage=newmessage' method='post'>
<input type='submit' value='Pokušajte ponovno' class='submit' />
</form>";
exit;
}
elseif(strlen($subject)) < 1){ //it should look like this: elseif(strlen($subject) < 1){
echo "Nije moguće poslati poruku bez Naslova. <br /><br />
<form action='index.php?page=mojprofil&subpage=newmessage' method='post'>
<input type='submit' value='Pokušajte ponovno' class='submit' />
</form>";
exit;
}
else{
$insert = mysql_query("INSERT INTO pm_inbox SET from_user = '".$fromuser."', to_user = '".$touser."', subject = '".$subject."', body = '".$body."'") OR die("Nije moguće poslati poruku: <br />" .mysql_error());
if($insert){ echo 'Poruka uspješno poslana';}
if(!$insert) { echo 'Poruka nije poslana. ';}
}