balkan7 Posted October 31, 2006 Share Posted October 31, 2006 i heed help for category and cd, not insert in mysql only insert ID, and in View Categry show Blank page ...base.sql[code]CREATE TABLE `software` ( `id` INT(250) NOT NULL AUTO_INCREMENT, `sifra` INT(25) NOT NULL, `naslov` VARCHAR(250) NOT NULL, `opis` TEXT NOT NULL, `kat_id` INT(25) NOT NULL, `cd_id` INT(25) NOT NULL, `novo` TINYINT(1) NOT NULL, `datum` VARCHAR(250) NOT NULL, `validen` TINYINT(1) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM;CREATE TABLE `software_kategorija` ( `id` INT(25) NOT NULL AUTO_INCREMENT, `kategorija` VARCHAR(250) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM;CREATE TABLE `software_cd` ( `id` INT(25) NOT NULL AUTO_INCREMENT, `cd` VARCHAR(250) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM; [/code]index.php[code]<?php//------------------------------------------//database connectionmysql_connect("localhost", "xxx", "xxx") or die(mysql_error());mysql_select_db("xxx") or die(mysql_error());//end database connection//------------------------------------------//------------------------------------------//echo out a navigation panelecho "<center><a href='index.php'>Pregled na Kategoerii</a> | <a href='index.php?action=dodaj'>Dodaj SoftwareAdd Tutorial</a></center>";//------------------------------------------//------------------------------------------//begin main navigation (tutorials.php?action=)switch($_GET['action']){ //------------------------------------------ //this case adds a tutorial. //pretty self-explanitory //------------------------------------------ case "dodaj": //if the form to enter a new //tutorial hasn't been submitted, //show it if(!isset($_POST['dodaj'])) { echo " <table border='0' cellpadding='0' cellspacing='0' width='500'> <form action='$self?action=dodaj' method='post'> <tr> <td>Sifra:</td> <td><input type='hidden' name='sifra'></td> </tr> <tr> <td>Naslov:</td> <td><input type='text' name='naslov'></td> </tr> <tr> <td>Opis:</td> <td><textarea name='opis' cols='40' rows='5'></textarea></td> </tr> <tr> <td>Kategorija:</td> <td> <select name='kategorija'> <option>- Izberi -</option> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $query = mysql_query("SELECT * FROM software_kategorija ORDER BY id ASC") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo "<option value='$row[id]'>$row[kategorija]"; } echo " </select> </td> </tr> <tr> <td>CD & DVD:</td> <td> <select name='cd'> <option>- Izberi -</option> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $query = mysql_query("SELECT * FROM software_cd ORDER BY id ASC") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo "<option value='$row[id]'>$row[cd]"; } echo " </select> </td> </tr> <tr> <td>Novo?</td> <td><input type='checkbox' name='novo' value='1' checked></td> </tr> <tr> <td colspan='2'><center><input type='submit' name='dodaj' value='Submit New Software'></center></td> </tr> </form> </table> ";}//else, error check, enter itelseif(isset($_POST['dodaj'])){ $string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $sifra = ""; for($i=0; $i<5; $i++){ $y = rand(0,strlen($string)-1); $sifra .= $string[$y]; } $naslov = mysql_real_escape_string(strip_tags($_POST['naslov'])); $opis = mysql_real_escape_string(strip_tags($_POST['opis'])); $kategorija = mysql_real_escape_string(strip_tags($_POST['kategorija'])); $cd = mysql_real_escape_string(strip_tags($_POST['cd'])); $novo = mysql_real_escape_string($_POST['novo']); $datum = date("m/d/Y"); //we begin error checking.... $error_msg = array(); if(empty($naslov)) { $error_msg[] = "Please insert a naslov!<br />"; } if(empty($opis)) { $error_msg[] = "Please insert a opis!<br />"; } if(empty($kategorija)) { $error_msg[] = "Please insert a kategorija!<br />"; } if(empty($cd)) { $error_msg[] = "Please select CD!<br />"; } //print the errors, if any if(count($error_msg)>0) { echo "<strong>ERROR:</strong><br>\n"; foreach($error_msg as $err) echo "$err"; } //everythings ok, insert it to the DB else { $sql = "INSERT INTO software (sifra, naslov, opis, kat_id, cd_id, novo, datum, validen) VALUES ('$sifra', '$naslov', '$opis', '$kat_id', '$cd_id', '$novo', '$datum', '1')"; mysql_query($sql) or die(mysql_error()); echo "Softwerot e uspesno dodaden, za pregled!"; } } break; //------------------------------------------ //this case gets the specified [ID] in the url //(tutorials.php?action=viewcategory&id=[ID] //and gets all the tutorials listed under that //category ID (cat_id) //------------------------------------------ case "pregled": //if there is an ID given... if($_GET['id']) { //get the id, put it into a variable, cast to an INT //(for security purposes) $id = (int)$_GET['id']; $query = mysql_query("SELECT * FROM software WHERE kat_id = '$id' AND validen = '1'") or die(mysql_error()); //if no results, show that there are no tutorials //for that category if(mysql_num_rows($query) == 0) { echo "Nema software vo ovaa Kategorija!"; } //else, there is..show em else { echo "<h1>Softwares</h1>"; //loop through the tutorials //show all tutorials echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; while($row = mysql_fetch_array($query)) { echo " <tr> <td>Sifra:</td> <td><b>$row[sifra]</b></td> </tr> <tr> <td>Naslov:</td> <td><b>$row[naslov]</b></td> </tr> <tr> <td>Opis:</td> <td>$row[opis]</td> </tr> <tr> <td>Kategorija:</td> <td>$row[kat_id]</td> </tr> <tr> <td>CD & DVD:</td> <td>$row[cd_id]</td> </tr> <tr> <td>Novo:</td> <td>$row[novo]</td> </tr> <tr> <td>Datum:</td> <td>$row[datum]</td> </tr> <tr> <td>Izmeni:</td> <td colspan='2'><b><a href='$self?akcija=izmeni&id=$row[id]'>Izmeni</a></b></td> </tr> <tr> <td colspan='2'><hr /></td> </tr> "; } echo "</table>"; }}else{ echo "Momentalno nema Softwares!";}break;//------------------------------------------//this case gets the given [ID]//action=viewtutorial&id=[ID]//and gets that tutorial ID from the database//and displays it!//------------------------------------------case "izmeni"://if there is an ID given..if($_GET['id']){ //set $id to the URL id, cast to an INT //for security purposes $id = (int)$_GET['id']; //query the database $query = mysql_query("SELECT * FROM software WHERE id = '$id'") or die (mysql_error()); //if no rows returned... if(mysql_num_rows($query) == 0) { echo "That ID is not in the database!"; } //else, show it! else { //update the views for this tutorial! $popravi = mysql_query("UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kat_id', cd_id = '$cd_id', novo = '$novo' WHERE id = '$id'") or die(mysql_error()); //loop through the database while($row = mysql_fetch_array($query)) { echo " <table border='0' cellpadding='0' cellspacing='0' width='500' style='border: 1px solid black; padding: 3px;'> <tr> <td colspan='2'>Software: <b>$row[naslov]</b></td> </tr> <tr> <td>Naslov:</td> <td><input type='text' name='naslov' value='$row[naslov]'></td> <tr> <td>Opis:</td> <td><textarea name='opis' cols='40' rows='5' value='$row[opis]'></textarea></td> </tr> <tr> <td>Kategorija:</td> <td> <select name='kategorija'> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $query = mysql_query("SELECT * FROM software_kategorija ORDER BY id ASC") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo "<option>- Izberi -</option>"; echo "<option value='$row[id]'>$row[kategorija]"; } echo " </select> </td> </tr> <tr> <td>CD & DVD:</td> <td> <select name='cd'> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $query = mysql_query("SELECT * FROM software_cd ORDER BY id ASC") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo "<option>- Izberi CD -</option>"; echo "<option value='$row[id]'>$row[cd]"; } echo " </select> </td> </tr> <tr> <td>Novo?</td> <td><input type='checkbox' name='novo' value='1' checked></td> </tr> <tr> <td colspan='2'><center><input type='submit' name='izmeni' value='Submit New Software'></center></td> </tr> </form> </table> </tr> <tr> <td colspan='2' style='border: 1px solid black;'><center><b>Software</b></center><br />$row[text]</td> </tr> <tr> "; } //---------------------------- //this part of the code //checks to see if the submitter //wants an email left for support //---------------------------- $new = "Novo"; if($row['novo'] == 1) { echo $new; } echo " </tr> <tr> <td><hr /></td> </tr> "; }//------------------------------------------//default case, this is shown default//in this instance, we are going to make the default case show//all the categories that you can view tutorials on//------------------------------------------$query = mysql_query("SELECT * FROM software_kategorija") or die(mysql_error());//if the number of rows returned is 0, then say, no categoriesif(mysql_num_rows($query) == 0){ echo "Nema Kategorii!";}//if anything else, then there has to be categories. show em.else{ echo "<h1>Software Kategorii:</h1> "; //while loop to loop through the database and display results! while($row = mysql_fetch_array($query)) { echo " <table border='0' cellpadding = '0' cellspacing='0' width='500'> <tr> <td>Ime za Kategorija:</td> <td>$row[kategorija]</td> </tr> <tr> <td><a href='$self?akcija=pregled&id=$row[id]'>Pogedni ja Kategorijata</a></td> </tr> <tr> <td><hr /></td> </tr> </table> "; } } break; } } //end navigation //------------------------------------------ ?>[/code]admin.php[code]<?php//------------------------------------------//database connectionmysql_connect("localhost", "xxx", "xxx") or die(mysql_error());mysql_select_db("xxx") or die(mysql_error());//end database connection//------------------------------------------//------------[IMPORTANT]-------------------// I would suggest adding this file to part// of a user system so it doesn't get viewed// by just anyone//------------[IMPORTANT]-------------------//------------------------------------------//echo out a navigation panelecho "<center><a href='index.php'>Pregled na Kategorija</a> | <a href='index.php?action=dodaj'>Dodaj Software</a> | <a href='admin.php'>Admin</a> | <a href='admin.php?action=napravi_kategorija'>Napravi Kategorija</a> | <a href='admin.php?action=napravi_cd'>Napravi CD & DVD</a></center>";//------------------------------------------//------------------------------------------//begin main navigation (tutorials.php?action=)switch($_GET['action']){ //-------------------------- // case to add a tutorial category //-------------------------- case "napravi_kategorija": //if the form to add a new category //isn't submitted, show one if(!isset($_POST['nova_kategorija'])) { echo " <form action='admin.php?action=napravi_kategorija' method='post'> <table border='0' cellpadding='0' cellspacing='0' width='500'> <tr> <td>Ime na Kategorijata:</td> <td><input type='text' name='kategorija' maxlength='25'></td> </tr> <tr> <td colspan='2'><center><input type='submit' name='nova_kategorija' value='Nova Kategorija!'></td> </tr> </table> </form> "; } //else, error check and then insert data to database! elseif(isset($_POST['nova_kategorija'])) { $category = mysql_real_escape_string(strip_tags($_POST['kategorija'])); //begin error reporting $error_msg = array(); if(empty($category)) { $error_msg[] = "No Category name entered!<br />"; } //print errors, if any if(count($error_msg)>0) { echo "<strong>ERROR:</strong><br>n"; foreach($error_msg as $err) echo "$err"; } //else, no errors, insert to the DB! else { $query = mysql_query("INSERT INTO software_kategorija (kategorija) VALUES ('$kategorija')") or die(mysql_error()); echo "Kategorijata e uspesno Napravena!"; } } break; //-------------------------- // case to add a tutorial category //-------------------------- case "napravi_cd": //if the form to add a new category //isn't submitted, show one if(!isset($_POST['novo_cd'])) { echo " <form action='admin.php?action=napravi_cd' method='post'> <table border='0' cellpadding='0' cellspacing='0' width='500'> <tr> <td>Kolku CD-a:</td> <td><input type='text' name='cd' maxlength='25'></td> </tr> <tr> <td colspan='2'><center><input type='submit' name='novo_cd' value='Novo CD!'></td> </tr> </table> </form> "; } //else, error check and then insert data to database! elseif(isset($_POST['novo_cd'])) { $category = mysql_real_escape_string(strip_tags($_POST['cd'])); //begin error reporting $error_msg = array(); if(empty($category)) { $error_msg[] = "No Category name entered!<br />"; } //print errors, if any if(count($error_msg)>0) { echo "<strong>ERROR:</strong><br>n"; foreach($error_msg as $err) echo "$err"; } //else, no errors, insert to the DB! else { $query = mysql_query("INSERT INTO software_cd (cd) VALUES ('$cd')") or die(mysql_error()); echo "CD e uspesno Napraveno!"; } } break; //-------------------------- //this case takes the submitted //form data of the admin form. //you can either validate, or delete //-------------------------- case "handle": //if nothing is submitted in the //row[] array, then error! if(empty($_POST['row'])) { echo "Nothing to delete/validate!"; } if(isset($_POST['delete_tutorials'])) { $delete_array = $_POST['row']; //loop through each individual //item in the array foreach($delete_array as $val) { //delete them! $query = "DELETE FROM software WHERE id = '$val'"; $result = mysql_query($query) or die(mysql_error()); } echo "Tutorial(s) deleted"; } elseif(isset($_POST['validate_tutorials'])) { $validate_array = $_POST['row']; //loop through each individual //item in the array foreach($validate_array as $val) { //update the status to 1 which means validated! $query = "UPDATE software SET validen = '1' WHERE id = '$val'"; $result = mysql_query($query) or die(mysql_error()); } echo "Soft(s) validated!"; } break; //-------------------------- //default case, we show //all tutorials with actions //-------------------------- default: $query = mysql_query("SELECT * FROM software WHERE validen = '1' ORDER BY id") or die(mysql_error()); echo "<h1>Unreviewed Tutorials</h1>"; if(mysql_num_rows($query) == 0) { echo "No tutorials unreviewed!"; } //there are rows, show the tutorials to //verify them else { //echo the submit buttons echo " <form action='admin.php?action=handle' method='post'> <table border='0' cellpadding='0' cellspacing='0' width='500'> <tr> <td><center>With Selected</center></td> </tr> <tr> <td colspan='2'><center><input type='submit' name='validate_tutorials' value='Validate'><input type='submit' name='delete_tutorials' value='Delete'></center></td> </tr> <tr> <td colspan='2'><hr /></td> </tr> "; //loop throught it to show them all while($row = mysql_fetch_array($query)) { echo " <tr> <td>Sifra:</td> <td>$row[sifra]</td> </tr> <tr> <td>Naslov:</td> <td>$row[naslov]</td> </tr> <tr> <td>Opis:</td> <td>$row[opis]</td> </tr> <tr> <td>Kategorija:</td> <td>$row[kat_id]</td> </tr> <tr> <td>CD:</td> <td>$row[cd_id]</td> </tr> <tr> <td>Novo:</td> <td>$row[novo]</td> </tr> <tr> <td>Datum:</td> <td>$row[datum]</td> </tr> <tr> <td><b>Mark</b></td> <td><input type='checkbox' name='row[]' value='$row[id]'></td> </tr> <tr> <td colspan='2'><hr /></td> </tr> "; } echo " </table> "; } break;}?> [/code] Link to comment https://forums.phpfreaks.com/topic/25690-not-show-category-and-others/ Share on other sites More sharing options...
sinisake Posted October 31, 2006 Share Posted October 31, 2006 Uf...puno koda,ali valjda ce neko skontati gresku.ako stignem,pogledacu :-)And now-translation:Uf,so much code,but i guess some one will find mistake.If i get little time i will try too... Link to comment https://forums.phpfreaks.com/topic/25690-not-show-category-and-others/#findComment-117238 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 hvala bogu da naidem na nekog nas :)hvala ti unaprijed :)translation, thank you :)i forget, sifra not generate auto code whit 5 charters .. Link to comment https://forums.phpfreaks.com/topic/25690-not-show-category-and-others/#findComment-117241 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 i fix for category, but now not show action=pregled and action=izmeni Link to comment https://forums.phpfreaks.com/topic/25690-not-show-category-and-others/#findComment-117253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.