Jump to content

PHP Script - Help


MikeFairbrother

Recommended Posts

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:
[code] 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>';
}
[/code]

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

$num = mysql_num_rows($result);

while($row = mysql_fetch_array($result)){[/code]

To this:
[code] $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']."'"));[/code]

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
Link to comment
Share on other sites

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

$num = mysql_num_rows($result);

while($row = mysql_fetch_array($result)){[/code]

To this:
[code] $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']."'"));[/code]
[/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
Link to comment
Share on other sites

"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.
Link to comment
Share on other sites

[code]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[/code]

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 }

[code]while($row = mysql_fetch_array($result)){[/code]
Link to comment
Share on other sites

[code]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>';[/code]

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.