Jump to content

Recommended Posts

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 connection
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
//end database connection
//------------------------------------------

//------------------------------------------
//echo out a navigation panel
echo "
<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 it
elseif(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 categories
if(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]
Link to comment
https://forums.phpfreaks.com/topic/25698-break-default-error/
Share on other sites

Parse error: syntax error, unexpected T_DEFAULT in /home/xxx/public_html/test/index.php on line 347

also 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]
Link to comment
https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117317
Share on other sites

[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 categories
if(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]
Link to comment
https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117330
Share on other sites

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 :(
Link to comment
https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117360
Share on other sites

[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 value
you generate $sifra after in code and it is OK
in 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]
Link to comment
https://forums.phpfreaks.com/topic/25698-break-default-error/#findComment-117394
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.