Jump to content


Photo

PHP Script - Help


  • Please log in to reply
5 replies to this topic

#1 MikeFairbrother

MikeFairbrother
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 April 2006 - 10:14 AM

Hi Guys,

Ok, I'm probably missing something really small, but I basically have a small personal message system for my website admin area. I'm just recoding it and things; and tidying up the code, but i've hit a problem.

I've got this:
if((((($_REQUEST['who'] == 1) || ($_REQUEST['who'] == 2) || ($_REQUEST['who'] == 3) || ($_REQUEST['who'] == 4) || ($_REQUEST['who'] == 5))))){
 
 $num = mysql_num_rows(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'")); 
 $row = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'"));
 
 mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row['username']."\",\"".$_REQUEST['msg_from']."\")"); 
   }
   echo 'Your message has been sent to '.$num.' users.<p><a href="privmsgs.php">Go Back to Inbox</a>';
  
  }elseif(((($_REQUEST['who'] == UK) || ($_REQUEST['who'] == US) || ($_REQUEST['who'] == CA) || ($_REQUEST['who'] == AU)))){
 
 $num = mysql_num_rows(mysql_query("SELECT * FROM staff where hotel='".$_REQUEST['who']."'")); 
 $row = mysql_fetch_array(mysql_query("SELECT * FROM staff where hotel='".$_REQUEST['who']."'")){
 
  mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row['username']."\",\"".$_REQUEST['msg_from']."\")");
   }
   echo 'Your message has been sent to '.$num.' users.<p><a href="privmsgs.php">Go Back to Inbox</a>';
  
 }elseif($_REQUEST['who'] == 0){
 
 $num1 = mysql_num_rows(mysql_query("SELECT * FROM staff where level='1'")); 
 $num2 = mysql_num_rows(mysql_query("SELECT * FROM staff where level='2'")); 
 $num3 = mysql_num_rows(mysql_query("SELECT * FROM staff where level='3'")); 
 $num4 = mysql_num_rows(mysql_query("SELECT * FROM staff where level='4'"));

 $row1 = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='1'")){ 
  mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row1['username']."\",\"".$_REQUEST['msg_from']."\")"); 
}
 $row2 = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='2'")){
  mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row2['username']."\",\"".$_REQUEST['msg_from']."\")"); 
}
 $row3 = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='3'")){
  mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row3['username']."\",\"".$_REQUEST['msg_from']."\")"); 
} 
 $row4 = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='4'")){
 mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row4['username']."\",\"".$_REQUEST['msg_from']."\")"); 
}
 $num = $num1 + $num2 + $num3 + $num4;
 echo 'Your message has been sent to '.$num.' users.<p><a href="privmsgs.php">Go Back to Inbox</a>'; 
 }

Basically, it all used to work, untill I changed
$sql = "SELECT * FROM staff where level='".$_REQUEST['who']."'";
 $result = mysql_query($sql); 
 
 $num = mysql_num_rows($result);
 
 while($row = mysql_fetch_array($result)){

To this:
$num = mysql_num_rows(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'")); 
 $row = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'"));

I think there may be something wrong with that.

Apart from that, everything else seems to work :)

Any help is appreciated.

THANKS in advance,
Mike

#2 TheUkSniper

TheUkSniper
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 08 April 2006 - 10:21 AM

Basically, it all used to work, untill I changed
$sql = "SELECT * FROM staff where level='".$_REQUEST['who']."'";
 $result = mysql_query($sql); 
 
 $num = mysql_num_rows($result);
 
 while($row = mysql_fetch_array($result)){

To this:
$num = mysql_num_rows(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'")); 
 $row = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'"));
[/quote]

no immediate probs in ur code but if tht was exactly what u have changed.. u started a while function on the original and then stopped using it on the replaced code.. that may be a problem if u need that function to run..

why not just change the code back :S

#3 MikeFairbrother

MikeFairbrother
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 April 2006 - 10:24 AM

"why not just change the code back :S"

I'd rather not change it back, it's like 5 lines of coding when you only really need one.

It's a very big file, the whole PM system runs off the one privmsgs.php file and im trying to making it just as efficient, with un-needed coding.

They both work in exactly the same way; its just for some reason, it isnt processing correctly.


#4 TheUkSniper

TheUkSniper
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 08 April 2006 - 10:40 AM

if((((($_REQUEST['who'] == 1) || ($_REQUEST['who'] == 2) || ($_REQUEST['who'] == 3) || ($_REQUEST['who'] == 4) || ($_REQUEST['who'] == 5)))))    >>> { <<<

$num = mysql_num_rows(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'")); 
$row = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'"));

mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row['username']."\",\"".$_REQUEST['msg_from']."\")"); 
  >>> } <<<
   echo 'Your message has been sent to '.$num.' users.<p><a href="privmsgs.php">Go Back to Inbox</a>';
  
>>>  } <<< elseif

well im guessin u need that while there because you open one bracket yet close it twice..
the code u changed has that bracket so im suprised u havent got a parse error for an unexpected }

while($row = mysql_fetch_array($result)){


#5 MikeFairbrother

MikeFairbrother
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 April 2006 - 10:51 AM

Below - sorry I wanted to delete this post but can't :)

#6 MikeFairbrother

MikeFairbrother
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 April 2006 - 02:00 PM

if((((($_REQUEST['who'] == 1) || ($_REQUEST['who'] == 2) || ($_REQUEST['who'] == 3) || ($_REQUEST['who'] == 4) || ($_REQUEST['who'] == 5))))){

$num = mysql_num_rows(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'")); 
$row = mysql_fetch_array(mysql_query("SELECT * FROM staff where level='".$_REQUEST['who']."'"));

mysql_query("INSERT INTO privmsgs (msg_title, msg_txt, msg_read, msg_date, msg_time, msg_ip, msg_to, msg_from) VALUES(\"".$_REQUEST['subject']."\",\"".nl2br($_REQUEST['message'])."\",\"0\",\"".date('j-m-Y')."\",\"".time()."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$row['username']."\",\"".$_REQUEST['msg_from']."\")"); 
   }
   echo 'Your message has been sent to '.$num.' users.<p><a href="privmsgs.php">Go Back to Inbox</a>';

It echos how many people it "should" have been sent too, but dosent actually send/input into database...
(Sorry for double post)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users