Thought it was too good to last! Smitten with my own success(?) I have also done a form which allows the sending of the same email to either all members or just the committee members. Form contains 2 radio buttons, same name (sendit) but with the values all / admins. For test purposes I am simply listing email addresses and using barebones code on the webserver. Obviously when uploading I shall use prepared statements etc.
Form is processed by a php page. Choosing the all option works perfectly, every member’s email address is listed, no probs. Choosing the admin option produces nothing, zilch, nada, just a blank screen, not even an error message. The only difference is in the sql but I’m sure that’s correct.
Because there are only 2 possible choices I have just written an if for each one. Should I write an else instead? Code follows:
<?php
include('joinin.inc.php');
$conn = dbconnect('query');
//get the radio button the user checked
$alloradmin = $_POST['sendit'];
if ($alloradmin=="all")
{
//send to all members
$sql = 'select emailadd from members';
$allres = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($allres))
{foreach ($row as $allmems){echo $allmems."<br/>";}
}
}
if ($alloradmin=="admins")
{
//send only to committee members
$somesql = "select emailadd from members where status='cm'";
$someres = mysqli_query($conn,$somesql);
while ($row = mysqli_fetch_assoc($someres))
{foreach ($row as $somemems){echo $somemems."<br/>";}
}
}
?>