I enjoy learning and doing things on my own, but I have run into a pickle that I don’t know how to fix.
I am trying to write a php mass mailer for an announcement system that I can activate within an admin page via a button.
Here is what the current script looks like.
function sendStreamAnnounce(){
global $database, $session, $mailer, $form;
$q = "SELECT username,email"
."FROM ".TBL_USERS."";
$result = $database->query($q);
$num_rows = mysql_numrows($result);
for($i=0; $i<$num_rows; $i++){
$email = mysql_result($result,$i,"email");
/* Attempt to send the email with new password */
if($mailer->sendStreamAnnounce($email))
$_SESSION['mailed'] = true;
else{
$_SESSION['forgotpass'] = false;
}
header("Location: ".$session->referrer);
}
}
The current set up leaves me with this
I’ve somehow adapted this from a “I forgot my password” php script that came with a tutorial-esque backend I am using. I realize some things like “$_SESSION” probably aren’t needed.
Any help is welcomed! I know many people don’t like spoonfeeding, so hints would help me a ton too.
Thank you guys in advance!
Edit: I fixed it on my own / with Arun’s help!
function sendStreamNotice(){
global $database, $session, $mailer, $form;
$q = "SELECT username,email "
."FROM ".TBL_USERS."";
$result = $database->query($q);
$num_rows = mysql_num_rows($result);
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
return;
}
if($num_rows == 0){
echo "Database table empty";
return;
}
for($i=0; $i<$num_rows; $i++){
$email = mysql_result($result,$i,"email");
$user = mysql_result($result,$i,"username");
/* Attempt to send the email with new password */
if($mailer->sendStreamNotice($user,$email))
$_SESSION['mailed'] = true;
else{
$_SESSION['forgotpass'] = false;
}
header("Location: ".$session->referrer);
}
}
The email went through just fine!
use
$num_rows = mysql_num_rows($result);instead ofmysql_numrows($result);