Hi Everyone I'm hoping someone could help me out please. I have a database of names and email addreses with the following columns:
user_id (auto increments)
user_name
user_email
user_email_sent
Basically I have a form (for myself) that returns all the rows in the database and next to each row I have a submit button that when pressed will send out an email to all the users. What I want to do is keep a count of how many times I've sent that particular email which will update the user_email_sent column by incrementing it by one every time I click the button. I've tried everything but the kitchen sink but I can't get my scripts to work. I'm sure I'm almost there but not quite and was wondering if someone could possibly help me out please?
Here's the form that returns all the rows with the submit button:
$query = "SELECT * FROM tbl_users order by user_name asc";
$result = mysql_query($query) or die(mysql_error());
echo "<form action='process.php' method='post'>";
echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Email</th> <th>Email Sent </th><th>Send Email</th></tr>";
while($row = mysql_fetch_array($result)){
$user_id = $row['user_id'];
$user_email_sent = $row['user_email_sent'];
echo "<tr><td>";
echo $row['user_name'];
echo "</td><td>";
echo $row['user_email'];
echo "</td><td>";
echo $row['user_email_sent'];
echo "</td><td>";
echo "<input type='submit' value='Send Mail' name='submit'>";
echo "</td></tr>";
}
echo "</table>";
echo "</form>";
And here is the form processor:
if ($_POST["$submit"])
{
$user_id = $_POST['$user_id'];
$user_email_sent = $_POST['$user_email_sent'];
$sql = "UPDATE tbl_users SET user_email_sent = $user_email_sent+1 WHERE user_id=$user_id";
$result = mysql_query($sql);
echo "Email Sent.";
}
Can anyone see where I'm going wrong? I haven't added the mail function yet, I just wanted to get the incrementing right first.
Any help would be greatly appreciated. Thanks!