I've a form on my website through which visitor can post message including email address. The form inputs are stored in MySql database.
To prevent the visitor from posting the message over and over using same e-mail address, I want to create a ban & unban application with html form and php where a single e-mail address or a list of e-mail addresses can be banned with that form.
I'm trying to implement the following codes for this purpose but the code can't update the value (0 & 1) of column banned to the database.
The form is as following:
<title>Ban / Remove Bans</title><form name="form1" method="post" action="">
<h3>Ban/Unban Users</h3>
<p>To ban/unban multiple users type <strong>EMAILS</strong> separated by <strong>spaces.
</strong>Banned users will not be able to login.<strong> <br>
</strong>To ban/unban a single user, just enter one email. </p>
<p><strong>*Note:</strong> Once the user is banner, he/she will never be able
to register new account with same email address.</p>
<p>
<textarea name="id" cols="40" id="id"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Ban">
<input name="Submit" type="submit" id="Submit" value="Unban">
</p>
</form>
and the php syntax is as following:
<?php
if (($_POST['Submit'] == 'Ban') )
{
$did = explode(' ',$_POST['id']);
foreach ($did as $del)
{
if (!empty($del))
{
mysql_query("update users set banned='1'
WHERE `user_email`='$del'
",$link) or die("Failed:" . mysql_error());
}
}
echo "done..";
}
if (($_POST['Submit'] == 'Unban') )
{
$did = explode(' ',$_POST['id']);
foreach ($did as $del)
{
if (!empty($del))
{
mysql_query("update users set banned='0'
WHERE `user_email`='$del'
",$link) or die("Failed:" . mysql_error());
}
}
echo "<h3>done..</h3>";
}
?>
and MySql syntax is as following:
$colname_test = "-1";
if (isset($_GET['id'])) {
$colname_test = $_GET['id'];
}
mysql_select_db($database_x, $x);
$query_test = sprintf("SELECT id, name, user_email, comment, banned FROM users WHERE id = %s ORDER BY id DESC", GetSQLValueString($colname_test, "int"));
$test = mysql_query($query_test, $x) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);
Would an advanced level programmer like to guide me to point out the problem and solve it?
Thanks,