The_Black_Knight Posted October 24, 2007 Share Posted October 24, 2007 Image of the admin site for my school index site. //Admin Area include '../include/dbconnect.php'; include '../include/style.php'; $username = $_POST['username']; $password = $_POST['password']; $query = "SELECT * FROM ".$dbprefix."users WHERE username='$username'"; $result = mysql_query($query); $data = mysql_fetch_object($result); if($data->pass!=md5($password)){ print "<html>"; print "<body>"; print "<title>".$pagetitel." - Admin Area</title>"; print "<link rel=\"icon\" href=\"../../images/favicon".$fileextension."\" type=\"image/x-icon\">"; print "<link rel=\"shortcut icon\"href=\"../../images/favicon".$fileextension."\" type=\"image/x-icon\">"; print "<link rel=\"stylesheet\" type=\"text/css\" href=\"../include/style.css\">"; print "<body bgcolor=".$browserbg.">"; print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"750\" align=\"center\" bordercolor=".$bordercolor." bgcolor=".$framebg.">"; print "<tr>"; print "<td align=\"center\"><img border=\"0\" src=\"./../../images/logo".$logofileextension."\" align=\"center\" width=\"720\">"; print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"720\" align=\"center\" bordercolor=".$bordercolor.">"; print "<tr><td bgcolor=".$browserbg." align=\"center\" colspan=\"3\"><font color=".$fontcolor." face=".$font." size=\"3\"><b>Admin Area</b></font></td></tr>"; print "</table>"; print "<br><br><br>"; //Sorting function $default_sort = 'post_code'; $allowed_order = array ('id','name', 'address', 'post_code', 'city', 'phone', 'url', 'email', 'latitude', 'longitude'); if (!isset ($order) ||!in_array ($order, $allowed_order)) { $order = $default_sort; } else { $order = $order; } if (!isset ($list)) { $list = "DESC"; } else { $list = $list; } if ($list == "ASC") { $list = "DESC"; } elseif ($list == "DESC") { $list = "ASC"; } else { $list = "ASC"; } $query = "SELECT id,name,address,post_code,city,phone,url,email,latitude,longitude FROM ".$dbprefix."schools ORDER BY $order $list"; $result = mysql_query($query) or die("MySQL Error: ".mysql_errno().": ".mysql_error()); $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; } //List displayed of schools print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"720\" align=\"center\" colspan=\"3\" bordercolor=".$bordercolor.">"; print "<tr>"; print "<td colspan=\"11\" align=\"center\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Schools in Database</b></font></td>"; print "</tr>"; print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><img src=\"../images/checkbox.png\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=id&list=$list>ID</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=name&list=$list>Name</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=address&list=$list>Address</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=post_code&list=$list>Zip/Post Code</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=city&list=$list>City</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=phone&list=$list>Phone</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=url&list=$list>URL</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=email&list=$list>Email</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=latitude&list=$list>Latitude</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><a href=$PHP_SELF?order=longitude&list=$list>Longitude</a></font></td>"; print "</tr>"; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { if ($i % $colsperrow == 0) { print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><div class=\"checkbox\">$checkbox</div><input type=\"checkbox\" name=\"schools[]\" value=\"".$row['id']."\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['id'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['name'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['address'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['post_code'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['city'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".$row['phone']."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><a href=".htmlspecialchars($row['url'])." target='_blank'>HP</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><a href=mailto:".htmlspecialchars($row['email']).">Contact</a></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['latitude'])."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars($row['longitude'])."</font></td>"; print "</tr>"; }} I am not getting the ID(s), that I need to run the delete/alter query. [hr] //Example I found on the net $checkboxes = $_REQUEST['schools']; //count how many id is actually present $countchkboxes = count($checkboxes); //use the for loop to retrieve each id for ($i = 0; $i < $checkboxes; $i++) { //retrieve value for ids and leave a comma after each one. //if value is blank then don't put a comma $retrievecb.= (($retrievecb != '') ? ", " : "") . intval($countchkboxes[$i]); } //Remove-Delete option!!!! if($_REQUEST[remove] == "remove"){ $remove = "DELETE FROM ".$dbprefix."schools WHERE id IN (".$retrievecb.")"; $result = mysql_query($remove); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" width=\"720\" bordercolor=".$bordercolor.">"; print "<td align=\"center\" colspan=\"4\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Remove/Alter/Add a School</b></font></td>"; print "<form action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Remove\"></td>"; print "<input type=\"hidden\" name=\"remove\" value=\"remove\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Alter\"></td>"; print "<input type=\"hidden\" name=\"alter\" value=\"alter\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Add\"></td>"; print "<input type=\"hidden\" name=\"add\" value=\"add\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</tr>"; print "</form>"; [hr] If the admin then have checked some checkmarks and presses "Alter" then the code should grap the information and display it in the fields below. If pressed "Remove", the the entry should be deleted in the DB. If pressed "Add", then the id space should be pre filled with next "free" id and all the other spaces should be clean so they would be ready to be filled with data. [hr] if($_REQUEST[alter] == "1"){ $alter= "INSERT INTO ".$dbprefix."schools Set id = '".$_REQUEST[id]."', name = '".$_REQUEST[name]."', address ='".$_REQUEST[address]."', post_code = '".$_REQUEST[post_code]."', city = '".$_REQUEST[city]."', phone = '".$_REQUEST[phone]."', url = '".$_REQUEST[url]."', email = '".$_REQUEST[email]."', longitude = '".$_REQUEST[longitude]."', latitude = '".$_REQUEST[latitude]."'"; $result = mysql_query($alter); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } while($row = mysql_fetch_object($result)) { print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"720\" align=\"center\" colspan=\"3\" bordercolor=".$bordercolor.">"; print "<form action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td colspan=\"10\" align=\"center\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Alter/Add Schools in Database</b></font></td>"; print "</tr>"; print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">ID</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Name</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Address</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Zip/Post Code</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">City</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Phone</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">URL</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Email</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Latitude</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Longitude</font></td>"; print "</tr>"; print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"id\" value=\"$row->id\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"nema\" value=\"$row->name\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"address\" value=\"$row->address\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"post_number\" value=\"$row->post_number\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"city\" value=\"$row->city\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"phone\" value=\"$row->phone\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"url\" value=\"$row->url\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"email\" value=\"$row->email\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"latitude\" value=\"$row->latitude\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"longitude\" value=\"$row->longitude\"></font></td>"; print "</td>"; print "<tr>"; print "<td colspan=\"11\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Update/Add School\"></td>"; print "</tr>"; print "<input type=\"hidden\" name=\"alter\" value=\"1\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</form>"; print "</table>"; } print "<br><br>"; [hr] The blow part is the unnessecary if the Alter/Add option is using the same form foe alter or add a entry. [hr] //Add a School if($_REQUEST[add] == "add"){ $insert = "INSERT INTO ".$dbprefix."schools Set id = '".$_REQUEST[id]."', name = '".$_REQUEST[name]."', address ='".$_REQUEST[address]."', post_code = '".$_REQUEST[post_code]."', city = '".$_REQUEST[city]."', phone = '".$_REQUEST[phone]."', url = '".$_REQUEST[url]."', email = '".$_REQUEST[email]."', longitude = '".$_REQUEST[longitude]."', latitude = '".$_REQUEST[latitude]."'"; $result = mysql_query($insert); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } while($row = mysql_fetch_object($result)){ $nr = ($numrows + 1); print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" width=\"720\" bordercolor=".$bordercolor.">"; print "<td align=\"center\" colspan=\"2\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Add a School</b></font></td>"; print "<form action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">ID</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"id\" value=\"".$nr."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Name</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"name\" value=\"".$row->name."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Address</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"address\" value=\"".$row->address."\">"; print "</td>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">ZIP/Post Code</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"post_code\" value=\"".$row->post_code."\">"; print "</td>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"> <font color=".$fontcolor." face=".$font." size=\"2\">City</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"city\" value=\"".$row->city."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Phone</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"phone\" value=\"".$row->phone."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">URL</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"url\" value=\"".$row->url."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Email</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"email\" value=\"".$row->email."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Latitude</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"latitude\" value=\"".$row->latitude."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Longitude</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"longitude\" value=\"".$row->longitude."\">"; print "</td>"; print "<tr>"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Add new School\"></td>"; print "</tr>"; print "<input type=\"hidden\" name=\"add\" value=\"add\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</form>"; print "</table>"; } print "<br><br>"; [hr] //Frontend Settings Switcher if($_REQUEST[settings] == "settings"){ $update = "UPDATE ".$dbprefix."settings Set browserbg = '".$_REQUEST[browserbg]."', framebg = '".$_REQUEST[framebg]."', bordercolor ='".$_REQUEST[bordercolor]."', tablebg = '".$_REQUEST[tablebg]."', pagetitel = '".$_REQUEST[pagetitel]."', tablehead = '".$_REQUEST[tablehead]."', fontcolor = '".$_REQUEST[fontcolor]."', fileextension = '".$_REQUEST[fileextension]."', logofileextension = '".$_REQUEST[logofileextension]."', websiteurl = '".$_REQUEST[websiteurl]."', colsperrow = '".$_REQUEST[colsperrow]."', font = '".$_REQUEST[font]."' WHERE line = '1' "; $result = mysql_query($update); } else{ $query = "SELECT * FROM ".$dbprefix."settings" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } while($row = mysql_fetch_object($result)){ print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" width=\"720\" bordercolor=".$bordercolor.">"; print "<td align=\"center\" colspan=\"2\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Frontend Settings Switcher</b></font></td>"; print "<form name=\"settings\" action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Page Titel (max 25 characters)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"pagetitel\" value=\"".$row->pagetitel."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">!! NOT WORKING YET!!! Site Language (Default English)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<select name=\"language\" size=\"1\"><option value=\"english\">English</option><option value=\"danish\">Danish</option>"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Website URL (http://www.bla.bla)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"websiteurl\" value=\"".$row->websiteurl."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Website Email (bla@bla.bla)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"websiteemail\" value=\"".$row->websiteemail."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Favicon File Extension (Favicon.gif/.png/.ico)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"fileextension\" value=\"".$row->fileextension."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Logo File Extension (Logo.gif/.png/.ico)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"logofileextension\" value=\"".$row->logofileextension."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"> <font color=".$fontcolor." face=".$font." size=\"2\">Site Background (#3C3A36)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"browserbg\" value=\"".$row->browserbg."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Frame Background (#666666)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"framebg\" value=\"".$row->framebg."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Border Color (#585754)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"bordercolor\" value=\"".$row->bordercolor."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Table Background (#737373)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"tablebg\" value=\"".$row->tablebg."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Tableheader Background (#383C33)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"tablehead\" value=\"".$row->tablehead."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Columns Per Row (space in row boxes)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"colsperrow\" value=\"".$row->colsperrow."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Font Type (Verdana)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"font\" value=\"".$row->font."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td bgcolor=".$tablebg." align=\"center\"><font color=".$fontcolor." face=".$font." size=\"2\">Font Color (#FFFFFF)</font></td>"; print "<td bgcolor=".$tablebg." align=\"center\">"; print "<input type=\"text\" name=\"fontcolor\" value=\"".$row->fontcolor."\">"; print "</td>"; print "</tr>"; print "<tr>"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Save Settings\"></td>"; print "</tr>"; print "<input type=\"hidden\" name=\"settings\" value=\"settings\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</form>"; print "</table>"; } mysql_close($connection); print "<table><tr><td><br>"; print "</form>"; print "<form action=\"../../index.php\" method=\"post\">"; print "<tr>"; print "<td align=\"center\" width=\"180\"><input type=\"submit\" value=\"Back to Mainpage\">"; print "</tr>"; print "</form>"; print "</td></tr></table>"; print "<br></td></table>"; print "</body>"; print "</html>"; } ?> So what do I need help for? I need help to get ID(s) from the checkboxes and some help with the code for my Alter/Add form. Two smaller things: - How do I limit the character output from a data fetch (I only want the Latitude/Longitude in my "Schools in Database" list to print 6 characters)? - How do I get the "Alter/Add Schools in Database" table to become the same size as the others tables? Plz help me. I am quite new at PHP/Mysql and I need to get this done because it is a school assignment. Sorry, in advance for bad spelling/grammar Kind regards Jacob Quote Link to comment https://forums.phpfreaks.com/topic/74529-problems-with-checkboxes-and-some-other-stuff/ Share on other sites More sharing options...
Toshiba23 Posted October 24, 2007 Share Posted October 24, 2007 You're going to need to have the checkboxes in an array form for when they are posted to the next script... such as: <input type="checkbox" name="school[]" value="{SCHOOL_ID}"> the name="school[]" is the key part of that, so when you go to the next page, you can do this: $selected = $_POST['school']; foreach($selected as $key => $val){ if($val){ // If it's checked $school_id = $val; // Do script for the checked box. } } as for the longitude, lat thing you want fixed, have this: print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars(substr($row['latitude'], 0, 6))."</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\">".htmlspecialchars(substr($row['longitude'], 0, 6))."</font></td>"; www.php.net/substr - Function used for cropping strings Hope this helps =) Quote Link to comment https://forums.phpfreaks.com/topic/74529-problems-with-checkboxes-and-some-other-stuff/#findComment-376798 Share on other sites More sharing options...
The_Black_Knight Posted October 24, 2007 Author Share Posted October 24, 2007 Thx, but I am still lost at the checkboxes. And quite lost at how I should make my Alter/Add function and combine it with the checkboxes. I know I need some sort of function saying when pressed Alter then run some code using the checbox data to get the specific entry from the DB, display it in the form. And if pressed Add then run some code that enter the id and leaves the rest of spaces empty. Then when pressing the "Update/Add School" button then it should check if there before were chosen Alter or Add for what query to run (update or insert). Do you have a idea about how it could be done? Some of the needed code: $selected = $_POST['school']; foreach($selected as $key => $val){ if($val){ // If it's checked $school_id = $val; // Do script for the checked box. } } //Remove-Delete option!!!! if($_REQUEST[remove] == "remove"){ $remove = "DELETE FROM ".$dbprefix."schools WHERE id IN (".$school_id.")"; $result = mysql_query($remove); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" width=\"720\" bordercolor=".$bordercolor.">"; print "<td align=\"center\" colspan=\"5\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Remove/Alter/Add a School</b></font></td>"; print "<form action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Remove\"></td>"; print "<input type=\"hidden\" name=\"remove\" value=\"remove\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Alter\"></td>"; print "<input type=\"hidden\" name=\"alter\" value=\"alter\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "<td colspan=\"2\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Add\"></td>"; print "<input type=\"hidden\" name=\"add\" value=\"add\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</tr>"; print "</form>"; if($_REQUEST[add] == "add"){ $insert = "INSERT INTO ".$dbprefix."schools Set id = '".$_REQUEST[id]."', name = '".$_REQUEST[name]."', address ='".$_REQUEST[address]."', post_code = '".$_REQUEST[post_code]."', city = '".$_REQUEST[city]."', phone = '".$_REQUEST[phone]."', url = '".$_REQUEST."', email = '".$_REQUEST."', longitude = '".$_REQUEST[longitude]."', latitude = '".$_REQUEST[latitude]."'"; $result = mysql_query($insert); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } while($row = mysql_fetch_object($result)){ $nr = ($numrows + 1); } if($_REQUEST[alter] == "1"){ $alter= "INSERT INTO ".$dbprefix."schools Set id = '".$_REQUEST[id]."', name = '".$_REQUEST[name]."', address ='".$_REQUEST[address]."', post_code = '".$_REQUEST[post_code]."', city = '".$_REQUEST[city]."', phone = '".$_REQUEST[phone]."', url = '".$_REQUEST."', email = '".$_REQUEST."', longitude = '".$_REQUEST[longitude]."', latitude = '".$_REQUEST[latitude]."'"; $result = mysql_query($alter); } else{ $query = "SELECT * FROM ".$dbprefix."schools" or die ("Cant call the table! MySQL-Error: ".mysql_errno().": ".mysql_error().""); $result = mysql_query($query); } while($row = mysql_fetch_object($result)) { print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"720\" align=\"center\" colspan=\"3\" bordercolor=".$bordercolor.">"; print "<form action=\"admin.php\" method=\"post\">"; print "<tr>"; print "<td colspan=\"10\" align=\"center\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\"><b>Alter/Add Schools in Database</b></font></td>"; print "</tr>"; print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">ID</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Name</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Address</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Zip/Post Code</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">City</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Phone</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">URL</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Email</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Latitude</font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablehead."><font color=".$fontcolor." face=".$font." size=\"2\">Longitude</font></td>"; print "</tr>"; print "<tr>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"id\" value=\"$row->id\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"nema\" value=\"$row->name\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"address\" value=\"$row->address\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"post_number\" value=\"$row->post_number\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"city\" value=\"$row->city\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"phone\" value=\"$row->phone\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"url\" value=\"$row->url\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"email\" value=\"$row->email\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"latitude\" value=\"$row->latitude\"></font></td>"; print "<td align=\"center\" valign=\"middle\" bgcolor=".$tablebg." width='".$colwidth."%'><font color=".$fontcolor." face=".$font." size=\"2\"><input type=\"text\" name=\"longitude\" value=\"$row->longitude\"></font></td>"; print "</td>"; print "<tr>"; print "<td colspan=\"11\" bgcolor=".$tablebg." align=\"center\"><input type=\"submit\" value=\"Update/Add School\"></td>"; print "</tr>"; print "<input type=\"hidden\" name=\"alteradd\" value=\"1\">"; print "<input type=\"hidden\" name=\"user\" value=\"".$username."\">"; print "<input type=\"hidden\" name=\"pass\" value=\"".$password."\">"; print "</form>"; print "</table>"; } print "<br><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/74529-problems-with-checkboxes-and-some-other-stuff/#findComment-376951 Share on other sites More sharing options...
The_Black_Knight Posted October 25, 2007 Author Share Posted October 25, 2007 Please help me :'( Quote Link to comment https://forums.phpfreaks.com/topic/74529-problems-with-checkboxes-and-some-other-stuff/#findComment-378110 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.