simcoweb Posted July 23, 2006 Share Posted July 23, 2006 Here's a summary. This code extracts IP addresses, the date and the directory accessed from a MySQL database and displays it in a simple format/layout for viewing purposes. What i'd like to do is add the ability for the IP address to have a checkbox next to it in this display so the user can select which one(s) they'd like to ban. They would then select the respective IP's checkboxes and upon submit it would write these to a new table in the database called 'banned'. That part of the code I think I can muscle through. But the automatic display of the checkboxes that retain and pass the IP number is where I haven't a clue. Obviously it would work as a form function once they've selected the IP's they wish to ban. I could point the submit button action to something like 'banned.php' and have it write the results to the database. Once again, however, it's the extracting of the results from the MySQL database and having the checkbox displayed next to it that mystifies me. Here's my simple code right now that summons the data:[code] // if successful it will connect to the database and display the info mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); echo $title . "<p>\n"; echo "</center><font face='Verdana' size='2'>Results show Ip address, date of entry, directory entered</font></center><p>"; print "<table align='center' width='600' border='0'><tr><td>"; // loop through array and print each line $query = "SELECT * FROM iplog"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['ip']. " - ". $row['date']. " - ".$row['directory']; echo "<br />"; }[/code]Any help would be appreciated. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 23, 2006 Share Posted July 23, 2006 To add a checkbox you'll want to something like this:[code]echo '<input type="checkbox" name="banip[]" value="' . $row['ip'] . '" /> ' . $row['ip']. ' - ' . $row['date'] . ' - ' . $row['directory'] . "<br />\n";[/code]You'll also want to create a form before the while loop and close it after the while loop so your code is this:[code]echo '<form action="banip.php" method="post">';while($row = mysql_fetch_array($result)){ echo '<input type="checkbox" name="banip[]" value="' . $row['ip'] . '" /> '; echo $row['ip']. ' - ' . $row['date'] . ' - ' . $row['directory'] . "<br />\n";}echo '<input type="submit" name="banips" value="Ban Selected" /></form>';[/code]Change banip.php in the action attribute for the form tag, to the page you want the form to be submitted to.Then when you go to get the ips selected from the previous page, you'll use this:[code]foreach($_POST['banip'] as $ipkey => $ip){ $sql = "INSERT INTO tbl_name (`ip`) VALUES ('$ip')"; mysql_query($sql);}[/code] Quote Link to comment Share on other sites More sharing options...
simcoweb Posted July 23, 2006 Author Share Posted July 23, 2006 Great! Ok, i'll insert this and keep you posted. It's clear and understandable even for a noobster like me :) Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 No problem, If you have any problems please post back. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.