balkan7 Posted October 31, 2006 Share Posted October 31, 2006 i have error in break; default: in last line, also in mysql for sifra insert one number not generate auto code whit 5 charters, someone help me !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', '$kategorija', '$cd', '$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?action=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 = '$kategorija', cd_id = '$cd', 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> "; } break;//------------------------------------------//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//------------------------------------------ default:$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 na Kategorijata:</td> <td>$row[kategorija]</td> </tr> <tr> <td><a href='$self?action=pregled&id=$row[id]'>Pogedni ja Kategorijata</a></td> </tr> <tr> <td><hr /></td> </tr> </table> "; } } break; } } //end navigation //------------------------------------------ ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/ Share on other sites More sharing options...
trq Posted October 31, 2006 Share Posted October 31, 2006 You might want to tell us WHAT the error is. Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117313 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 Parse error: syntax error, unexpected T_DEFAULT in /home/xxx/public_html/test/index.php on line 347also in mysql for sifra insert one number not generate auto code whit 5 charters.this is code for autogenerate sifra (KEY)[code]$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $sifra = ""; for($i=0; $i<5; $i++){ $y = rand(0,strlen($string)-1); $sifra .= $string[$y]; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117317 Share on other sites More sharing options...
trq Posted October 31, 2006 Share Posted October 31, 2006 You need to narrow down your problem then. Post the relevent code around line 347, help us help you, were not slaves.[quote]also in mysql for sifra insert one number not generate auto code whit 5 charters.[/quote]Sorry, but I have no idea what that sentence says. Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117326 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 [color=red]347 line ->[/color] default:[code] //---------------------------- $new = "Novo"; if($row['novo'] == 1) { echo "$new"; } echo " </tr> <tr> <td><hr /></td> </tr> "; } break;//------------------------------------------//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//------------------------------------------ default:$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)) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117330 Share on other sites More sharing options...
kenrbnsn Posted October 31, 2006 Share Posted October 31, 2006 Check that all of the curly braces "{ }" are matched. Somewhere in your code you have at least one too many closing brace "}". If you make sure your indentation is consistant throughout the code, you will find it quicker.Ken Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117335 Share on other sites More sharing options...
trq Posted October 31, 2006 Share Posted October 31, 2006 I think you have an extra } just before the break before the default but honestly, your code is pretty hard to read. Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117338 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 yes i have been removed extra } before break, but nothing [code]Parse error: syntax error, unexpected T_DEFAULT in /home/xxx/public_html/test/index.php on line 346[/code]i cant find mastake, and i know thorpe is very hard for read this code bacause i have translated for my language, i forget first to write in english :( Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117360 Share on other sites More sharing options...
kenrbnsn Posted October 31, 2006 Share Posted October 31, 2006 The problem of the code being hard to read has nothing to do with it not being written in English. It has everything to do with the indentation problem. Fix the indentation and you will find your curly brace problem.Ken Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117363 Share on other sites More sharing options...
sasa Posted October 31, 2006 Share Posted October 31, 2006 in table software field sifra is int type (your previous post) Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117379 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 [code]<td><input type='hidden' name='sifra'></td>[/code]its hidden for auto generate KEY whit 5 charters in date base. Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117383 Share on other sites More sharing options...
sasa Posted October 31, 2006 Share Posted October 31, 2006 [quote author=balkan7 link=topic=113348.msg460630#msg460630 date=1162313336][code]<td><input type='hidden' name='sifra'></td>[/code]its hidden for auto generate KEY whit 5 charters in date base.[/quote]it is nothing. you post variable sifra with no valueyou generate $sifra after in code and it is OKin http://www.phpfreaks.com/forums/index.php/topic,113339.0.html i see '`sifra` INT(25) NOT NULL,' you can not store string in that field[code] <tr> <td><hr /></td> </tr> "; }} //insert this break;//------------------------------------------//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//------------------------------------------[/code]and[code] "; } } break; } // } <= remove this //end navigation //------------------------------------------[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117394 Share on other sites More sharing options...
balkan7 Posted October 31, 2006 Author Share Posted October 31, 2006 thank you very much for your help and support, good work ! Quote Link to comment https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117534 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.