Errors with variables from while loops

Discussion in 'PHP' started by snowLee, Dec 9, 2009.

  1. #1
    I have this script but I get errors about the variables that I take from 3 while loops: $id_categorie, $id_subcategorie, $id_ssubcategorie. Please someone tell me where I am wrong.

    
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    </head>
    
    <body>
    <script type="text/javascript">
    function showHide(id){
       el = document.getElementById(id);
       el.style.display = (el.style.display != 'block')? 'block' : 'none';
    }
    </script>
    <?php
    include ("config.php");
    if(isset($_POST['submit'])) {
       
       
        $nume = $_POST['nume'];
        $tara = $_POST['tara'];
        $adresa = $_POST['adresa'];
        $telefon_mob = $_POST['telefon_mob'];
        $telefon_fix = $_POST['telefon_fix'];
        $fax = $_POST['fax'];
        $email = $_POST['email'];
        $web = $_POST['web'];
        $comentarii = $_POST['comentarii'];
        $observatii = $_POST['observatii'];
        $link_catalog = $_POST['link_catalog'];
        $link_preturi = $_POST['link_preturi'];
        $furnizor = $_POST['furnizor'];
        $concurent = $_POST['concurent'];
        $producator = $_POST['producator'];
       
        $sql = "INSERT INTO firme (nume,tara,adresa,telefon_mob,telefon_fix,fax,email,web,comentarii,observatii,link_catalog,
                                 link_preturi)
                        VALUES('$nume', '$tara', '$adresa', '$telefon_mob', '$telefon_fix',
                                 '$fax', '$email', '$web', '$comentarii', '$observatii',
                                 '$link_catalog', '$link_preturi')" ;
                       
        $result = mysql_query($sql) or die(mysql_error());
       
       
        $sql2 = "INSERT INTO id(id_firma, id_categorie, id_subcategorie,  id_ssubcategorie, producator, furnizor, client)
                        VALUES($nume, $id_categorie, $id_subcategorie, $id_ssubcategorie,$producator, $furnizor, $concurent)";
        $result = mysql_query($sql2) or die(mysql_error());
        echo "Datele au fost introduse";
       
       
       
        
           
    }
    else{   
    ?>
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
    <label>Nume firma</label><br />
    <input type ="text" name="nume" /><br />
    <label>Tara</label><br />
    <input type ="text" name="tara" /><br />
    <label>Adresa</label><br />
    <input type ="text" name="adresa" /><br />
    <label>Telefon Mobil</label><br />
    <input type ="text" name="telefon_mob" /><br />
    <label>Telefon Fix</label><br />
    <input type ="text" name="telefon_fix" /><br />
    <label>Fax</label><br />
    <input type ="text" name="fax" /><br />
    <label>Email</label><br />
    <input type ="text" name="email" /><br />
    <label>Adresa web</label><br />
    <input type ="text" name="web" /><br />
    <label>Comentarii</label><br />
    <input type ="text" name="comentarii" /><br />
    <label>Observatii</label><br />
    <input type ="text" name="observatii" /><br />
    <label>Link catalog</label><br />
    <input type ="text" name="link_catalog" /><br />
    <label>Link preturi</label><br />
    <input type ="text" name="link_preturi" /><br />
    
    
          <label><input type="checkbox" name="producator" value="checkbox" onclick="showHide('chk2'), showHide('chk3'), showHide('chk4')" />Producator</label><br/>
        <label><input type="checkbox" name="furnizor" value="checkbox" onclick="showHide('chk5'), showHide('chk6'), showHide('chk7')" />Furnizor</label><br/>
        <label><input type="checkbox" name="concurent" value="checkbox" onclick="showHide('chk8'), showHide('chk9'), showHide('chk10')" />Concurent</label><br/>
       
      <!--///////////////////////////////////Producator////////////////////////////////////////////////-->
     
        <select name="chk2" multiple size=10 style="display:none" id="chk2">
         <?php
       
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                 
                $id_categorie = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option  name='$id_categorie'  value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk3" multiple size=10 style="display:none" id="chk3">
     
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_subcategorie = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option  name='$id_subcategorie'  value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
            </select>
        <select name="chk4" multiple size=10 style="display:none" id="chk4">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option  name='$id_ssubcategorie  value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
        </select>
       
        <!--///////////////////////////////////Furnizor////////////////////////////////////////////////-->
       
       
       
            <select name="chk5" multiple size=10 style="display:none" id="chk5">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option  name='$id'  value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk6" multiple size=10 style="display:none" id="chk6">
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option  name='$id'  value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
        </select>
       
            <select name="chk7" multiple size=10 style="display:none" id="chk7">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option  name='$id_ssubcategorie'  value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
        </select>
       
       
        <!--///////////////////////////////////Concurent////////////////////////////////////////////////-->
       
        <select name="chk8" multiple size=10 style="display:none" id="chk8">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option  name='$id'  value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk9" multiple size=10 style="display:none" id="chk9">
     
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option  name='$id'  value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
            </select>
        <select name="chk10" multiple size=10 style="display:none" id="chk10">
      <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option  name='$id_ssubcategorie'  value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
            </select>
         <!--///////////////////////////////////////////////////////////////////////////////////--> 
       
         <input type ="submit" name="submit" value="Introdu datele" />
    
    </form>
    <?php
    }
    ?>
    
    </body>
    </html>
    
    
    
    
    
    
    PHP:

     
    snowLee, Dec 9, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    which line the error on?

    I think you have to write so:

    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    </head>
    
    <body>
    <script type="text/javascript">
    function showHide(id){
       el = document.getElementById(id);
       el.style.display = (el.style.display != 'block')? 'block' : 'none';
    }
    </script>
    <?php
    include ("config.php");
    if(isset($_POST['submit'])) {
    
    
        $nume = $_POST['nume'];
        $tara = $_POST['tara'];
        $adresa = $_POST['adresa'];
        $telefon_mob = $_POST['telefon_mob'];
        $telefon_fix = $_POST['telefon_fix'];
        $fax = $_POST['fax'];
        $email = $_POST['email'];
        $web = $_POST['web'];
        $comentarii = $_POST['comentarii'];
        $observatii = $_POST['observatii'];
        $link_catalog = $_POST['link_catalog'];
        $link_preturi = $_POST['link_preturi'];
        $furnizor = $_POST['furnizor'];
        $concurent = $_POST['concurent'];
        $producator = $_POST['producator'];
    
        $sql = "INSERT INTO firme (nume,tara,adresa,telefon_mob,telefon_fix,fax,email,web,comentarii,observatii,link_catalog,
                                 link_preturi)
                        VALUES('$nume', '$tara', '$adresa', '$telefon_mob', '$telefon_fix',
                                 '$fax', '$email', '$web', '$comentarii', '$observatii',
                                 '$link_catalog', '$link_preturi')" ;
    
        $result = mysql_query($sql) or die(mysql_error());
    
    
        $sql2 = "INSERT INTO id(id_firma, id_categorie, id_subcategorie,  id_ssubcategorie, producator, furnizor, client)
                        VALUES('$nume', '$id_categorie', '$id_subcategorie', '$id_ssubcategorie','$producator', '$furnizor', '$concurent')";
        $result = mysql_query($sql2) or die(mysql_error());
        echo "Datele au fost introduse";
    
    
    
    
    
    }
    else{
    ?>
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
    <label>Nume firma</label><br />
    <input type ="text" name="nume" /><br />
    <label>Tara</label><br />
    <input type ="text" name="tara" /><br />
    <label>Adresa</label><br />
    <input type ="text" name="adresa" /><br />
    <label>Telefon Mobil</label><br />
    <input type ="text" name="telefon_mob" /><br />
    <label>Telefon Fix</label><br />
    <input type ="text" name="telefon_fix" /><br />
    <label>Fax</label><br />
    <input type ="text" name="fax" /><br />
    <label>Email</label><br />
    <input type ="text" name="email" /><br />
    <label>Adresa web</label><br />
    <input type ="text" name="web" /><br />
    <label>Comentarii</label><br />
    <input type ="text" name="comentarii" /><br />
    <label>Observatii</label><br />
    <input type ="text" name="observatii" /><br />
    <label>Link catalog</label><br />
    <input type ="text" name="link_catalog" /><br />
    <label>Link preturi</label><br />
    <input type ="text" name="link_preturi" /><br />
    
    
          <label><input type="checkbox" name="producator" value="checkbox" onclick="showHide('chk2'), showHide('chk3'), showHide('chk4')" />Producator</label><br/>
        <label><input type="checkbox" name="furnizor" value="checkbox" onclick="showHide('chk5'), showHide('chk6'), showHide('chk7')" />Furnizor</label><br/>
        <label><input type="checkbox" name="concurent" value="checkbox" onclick="showHide('chk8'), showHide('chk9'), showHide('chk10')" />Concurent</label><br/>
    
      <!--///////////////////////////////////Producator////////////////////////////////////////////////-->
    
        <select name="chk2" multiple size=10 style="display:none" id="chk2">
         <?php
    
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
                $id_categorie = $row['id'];
                $categorie = $row['categorie'];
                echo "<option  name='$id_categorie'  value='$categorie'>$categorie<br />";
    
            }
            ?>
        </select>
        <select name="chk3" multiple size=10 style="display:none" id="chk3">
    
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_subcategorie = $row['id'];
                $subcategorie = $row['subcategorie'];
                echo "<option  name='$id_subcategorie'  value='$subcategorie'>$subcategorie<br />";
    
            }
            ?>
            </select>
        <select name="chk4" multiple size=10 style="display:none" id="chk4">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];
                echo "<option  name='$id_ssubcategorie  value='$ssubcategorie'>$ssubcategorie<br />";
    
            }
            ?>
        </select>
    
        <!--///////////////////////////////////Furnizor////////////////////////////////////////////////-->
    
    
    
            <select name="chk5" multiple size=10 style="display:none" id="chk5">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];
                echo "<option  name='$id'  value='$categorie'>$categorie<br />";
    
            }
            ?>
        </select>
        <select name="chk6" multiple size=10 style="display:none" id="chk6">
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];
                echo "<option  name='$id'  value='$subcategorie'>$subcategorie<br />";
    
            }
            ?>
        </select>
    
            <select name="chk7" multiple size=10 style="display:none" id="chk7">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];
                echo "<option  name='$id_ssubcategorie'  value='$ssubcategorie'>$ssubcategorie<br />";
    
            }
            ?>
        </select>
    
    
        <!--///////////////////////////////////Concurent////////////////////////////////////////////////-->
    
        <select name="chk8" multiple size=10 style="display:none" id="chk8">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];
                echo "<option  name='$id'  value='$categorie'>$categorie<br />";
    
            }
            ?>
        </select>
        <select name="chk9" multiple size=10 style="display:none" id="chk9">
    
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];
                echo "<option  name='$id'  value='$subcategorie'>$subcategorie<br />";
    
            }
            ?>
            </select>
        <select name="chk10" multiple size=10 style="display:none" id="chk10">
      <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);
                echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];
                echo "<option  name='$id_ssubcategorie'  value='$ssubcategorie'>$ssubcategorie<br />";
    
            }
            ?>
            </select>
         <!--///////////////////////////////////////////////////////////////////////////////////-->
    
         <input type ="submit" name="submit" value="Introdu datele" />
    
    </form>
    <?php
    }
    ?>
    
    </body>
    </html>
    
    Code (markup):
    I changed the $sql2 query.
     
    s_ruben, Dec 9, 2009 IP
  3. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    The errors:


    Notice: Undefined index: furnizor in C:\wamp\www\calor\add_firma.php on line 38

    Notice: Undefined index: concurent in C:\wamp\www\calor\add_firma.php on line 39

    Notice: Undefined variable: id_categorie in C:\wamp\www\calor\add_firma.php on line 66

    Notice: Undefined variable: id_subcategorie in C:\wamp\www\calor\add_firma.php on line 66

    Notice: Undefined variable: id_ssubcategorie in C:\wamp\www\calor\add_firma.php on line 66
     
    snowLee, Dec 9, 2009 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    I think your written script is not full. On line 66 is html code and there is no variable!!!
     
    s_ruben, Dec 9, 2009 IP
  5. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    I had some comments that I deleted before I put the script on this forum, that's why the errors were on line 66.

    The errors refer to this line :

    
     $sql2 = "INSERT INTO id(id_firma, id_categorie, id_subcategorie,  id_ssubcategorie, producator, furnizor, concurent)
                        VALUES('$nume', '$id_categorie', '$id_subcategorie', '$id_ssubcategorie','$producator', '$furnizor', '$concurent')"
    
    PHP:
    Anyway I put this page with the database on the server(because I worked in local host) and I didn't get any errors but when I look to the database I see that this $sql2 inserts zero for $id_categorie', '$id_subcategorie', '$id_ssubcategorie', where I should be some products name not zero :(.

    This si the table for this insert



    --
    -- Database: `puffymi_calor`
    --

    -- --------------------------------------------------------

    --
    -- Table structure for table `id`
    --

    CREATE TABLE IF NOT EXISTS `id` (
    `id` int(11) NOT NULL auto_increment,
    `id_firma` text NOT NULL,
    `id_categorie` int(11) NOT NULL,
    `id_subcategorie` int(11) NOT NULL,
    `id_ssubcategorie` int(11) NOT NULL,
    `producator` varchar(100) NOT NULL,
    `furnizor` varchar(100) NOT NULL,
    `concurent` varchar(100) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

    --
    -- Dumping data for table `id`
    --

    INSERT INTO `id` (`id`, `id_firma`, `id_categorie`, `id_subcategorie`, `id_ssubcategorie`, `producator`, `furnizor`, `concurent`) VALUES
    (1, '', 1, 0, 0, '', '', ''),
    (2, 'wqe', 0, 0, 0, 'checkbox', '', ''),
    (3, 'nume_firma', 0, 0, 0, 'checkbox', 'checkbox', 'checkbox');
     
    snowLee, Dec 10, 2009 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    add this variables just after $producator = $_POST['producator'];

    $id_categorie = $_POST['chk2'];
    $id_subcategorie = $_POST['chk3'];
    $id_ssubcategorie = $_POST['chk4'];
     
    s_ruben, Dec 10, 2009 IP
  7. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    I still get zero in each column from table id, even I put those variables :(
     
    snowLee, Dec 10, 2009 IP
  8. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #8
    Delete this lines
    
    echo '<br /><br /><b>Categorii</b><br /><br />';
             echo '<form action="#" method="POST">';
    
    Code (markup):
    everywhere in <select> tag.
     
    s_ruben, Dec 10, 2009 IP
  9. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    Thank you. I saw that and I deleted before, but still nothing.

    I used var_dump and I got this:

    NULL array(17) { ["nume"]=> string(14) "company_name12" ["tara"]=> string(12) "country_name" ["adresa"]=> string(7) "address" ["telefon_mob"]=> string(9) "000000111" ["telefon_fix"]=> string(9) "111110000" ["fax"]=> string(8) "00011000" ["email"]=> string(16) "sometng@mail.com" ["web"]=> string(15) "www.example.com" ["comentarii"]=> string(8) "coments " ["observatii"]=> string(12) "observations" ["link_catalog"]=> string(11) "links links" ["link_preturi"]=> string(12) "links links " ["furnizor"]=> string(8) "checkbox" ["chk5"]=> string(16) "Centrale termice" ["chk6"]=> string(15) "Sisteme termice" ["chk7"]=> string(35) "Centrale electrice cu tiraj natural" ["submit"]=> string(14) "Introdu datele" } Datele au fost introduse

    You can see that in the script

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    </head>
    
    <body>
    <script type="text/javascript">
    function showHide(id){
       el = document.getElementById(id);
       el.style.display = (el.style.display != 'block')? 'block' : 'none';
    }
    </script>
    <?php
    include ("config.php");
    if(isset($_POST['submit'])) {
       
       
        //if(!empty($_POST['nume']) && !empty($_POST['tara']) && !empty($_POST['adresa'] )
        //&& !empty($_POST['telefon_mob']) && !empty($_POST['telefon_fix']) && !empty($_POST['fax'])
        //&& !empty($_POST['email']) && !empty($_POST['web']) && !empty($_POST['comentarii'])
        //&& !empty($_POST['observatii']) && !empty($_POST['link_catalog']) && !empty($_POST['link_preturi'])
        //&& !empty($_POST['furnizor']) && !empty($_POST['clienti']) && !empty($_POST['producatori'])){
    
        $nume = $_POST['nume'];
        $tara = $_POST['tara'];
        $adresa = $_POST['adresa'];
        $telefon_mob = $_POST['telefon_mob'];
        $telefon_fix = $_POST['telefon_fix'];
        $fax = $_POST['fax'];
        $email = $_POST['email'];
        $web = $_POST['web'];
        $comentarii = $_POST['comentarii'];
        $observatii = $_POST['observatii'];
        $link_catalog = $_POST['link_catalog'];
        $link_preturi = $_POST['link_preturi'];
        $furnizor = $_POST['furnizor'];
        $concurent = $_POST['concurent'];
        $producator = $_POST['producator'];
    	$id_categorie = $_POST['chk2'];
    	$id_subcategorie = $_POST['chk3'];
    	$id_ssubcategorie = $_POST['chk4']; 
    	$id_categorie = $_POST['chk5'];
    	$id_subcategorie = $_POST['chk6'];
    	$id_ssubcategorie = $_POST['chk7']; 
    	$id_categorie = $_POST['chk8'];
    	$id_subcategorie = $_POST['chk9'];
    	$id_ssubcategorie = $_POST['chk10']; 
       
        $sql = "INSERT INTO firme (nume,tara,adresa,telefon_mob,telefon_fix,fax,email,web,comentarii,observatii,link_catalog,
                                 link_preturi)
                        VALUES('$nume', '$tara', '$adresa', '$telefon_mob', '$telefon_fix',
                                 '$fax', '$email', '$web', '$comentarii', '$observatii',
                                 '$link_catalog', '$link_preturi')" ;
                       
        $result = mysql_query($sql) or die(mysql_error());
       	var_dump($id_categorie);
    	var_dump($_POST);
        $sql2 = "INSERT INTO id(id_firma, id_categorie, id_subcategorie,  id_ssubcategorie, producator, furnizor, concurent)
                        VALUES('$nume', '$id_categorie', '$id_subcategorie', '$id_ssubcategorie','$producator', '$furnizor', '$concurent')";
        $result = mysql_query($sql2) or die(mysql_error());
        echo "Datele au fost introduse";
        //}
       
       
        
           
    }
    else{   
    ?>
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
    <label>Nume firma</label><br />
    <input type ="text" name="nume" /><br />
    <label>Tara</label><br />
    <input type ="text" name="tara" /><br />
    <label>Adresa</label><br />
    <input type ="text" name="adresa" /><br />
    <label>Telefon Mobil</label><br />
    <input type ="text" name="telefon_mob" /><br />
    <label>Telefon Fix</label><br />
    <input type ="text" name="telefon_fix" /><br />
    <label>Fax</label><br />
    <input type ="text" name="fax" /><br />
    <label>Email</label><br />
    <input type ="text" name="email" /><br />
    <label>Adresa web</label><br />
    <input type ="text" name="web" /><br />
    <label>Comentarii</label><br />
    <input type ="text" name="comentarii" /><br />
    <label>Observatii</label><br />
    <input type ="text" name="observatii" /><br />
    <label>Link catalog</label><br />
    <input type ="text" name="link_catalog" /><br />
    <label>Link preturi</label><br />
    <input type ="text" name="link_preturi" /><br />
    
    
          <label><input type="checkbox" name="producator" value="checkbox" onclick="showHide('chk2'), showHide('chk3'), showHide('chk4')" />Producator</label><br/>
        <label><input type="checkbox" name="furnizor" value="checkbox" onclick="showHide('chk5'), showHide('chk6'), showHide('chk7')" />Furnizor</label><br/>
        <label><input type="checkbox" name="concurent" value="checkbox" onclick="showHide('chk8'), showHide('chk9'), showHide('chk10')" />Concurent</label><br/>
       
      <!--///////////////////////////////////Producator////////////////////////////////////////////////-->
     
        <select name="chk2" multiple size=10 style="display:none" id="chk2">
         <?php
       
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                 
                $id_categorie = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option   value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk3" multiple size=10 style="display:none" id="chk3">
     
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_subcategorie = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option   value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
            </select>
        <select name="chk4" multiple size=10 style="display:none" id="chk4">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option   value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
        </select>
       
        <!--///////////////////////////////////Furnizor////////////////////////////////////////////////-->
       
       
       
            <select name="chk5" multiple size=10 style="display:none" id="chk5">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option   value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk6" multiple size=10 style="display:none" id="chk6">
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option  value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
        </select>
       
            <select name="chk7" multiple size=10 style="display:none" id="chk7">
             <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option   value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
        </select>
       
       
        <!--///////////////////////////////////Concurent////////////////////////////////////////////////-->
       
        <select name="chk8" multiple size=10 style="display:none" id="chk8">
         <?php
        $sql = "SELECT * FROM categorii ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $categorie = $row['categorie'];    
                echo "<option  value='$categorie'>$categorie<br />";
               
            }
            ?>
        </select>
        <select name="chk9" multiple size=10 style="display:none" id="chk9">
     
         <?php
        $sql = "SELECT * FROM subcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $subcategorie = $row['subcategorie'];    
                echo "<option  value='$subcategorie'>$subcategorie<br />";
               
            }
            ?>
            </select>
        <select name="chk10" multiple size=10 style="display:none" id="chk10">
      <?php
        $sql = "SELECT * FROM ssubcategorie ";
             $result = mysql_query($sql);    
                echo '<br /><br /><b>Categorii</b><br /><br />';
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id_ssubcategorie = $row['id'];
                $ssubcategorie = $row['ssubcategorie'];    
                echo "<option   value='$ssubcategorie'>$ssubcategorie<br />";
               
            }
            ?>
            </select>
         <!--///////////////////////////////////////////////////////////////////////////////////--> 
       
         <input type ="submit" name="submit" value="Introdu datele" />
    
    </form>
    <?php
    }
    ?>
    
    </body>
    </html>
    
    PHP:
     
    snowLee, Dec 10, 2009 IP
  10. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #10
    Delete the lines
    echo '<br /><br /><b>Categorii</b><br /><br />';
    Code (markup):
    in <select> tags too.
     
    s_ruben, Dec 10, 2009 IP
  11. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #11
    I deleted but I still get zeros in my id table from this $sql2.
     
    snowLee, Dec 10, 2009 IP
  12. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #12
    Can I access to the script??
     
    s_ruben, Dec 10, 2009 IP
  13. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #13
    The link to try the script.
     
    snowLee, Dec 10, 2009 IP
  14. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #14
    You must to set the names of select tags like this
    name="chk2[]", name="chk3[]"...
    and the $_POST["chk2"] becomes an array where values of the array are the multiple selected categories.

    It is the tips to rebuild your $sql2 query.
     
    s_ruben, Dec 10, 2009 IP
  15. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #15
    I did that, but please help me to understand how can I modify my $sql2 in this case. I put the picture with the id table on server.
     
    snowLee, Dec 10, 2009 IP
  16. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #16
    Explain in details what do you want to do!!
     
    s_ruben, Dec 10, 2009 IP
  17. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #17
    In the form I put some info about a company, then I have 3 checkboxes where I select if that company is a Producer, Manufacturer or Client. If one checkbox is checked, with js I show 3 <select></select>, that were hided. In those 3 select I bring from database the products:category: $categorie, sub-products: $subcategorie, sub-sub-products: $ssubcategorie. Using while loop I print out in <option> those 3.
    My logic is, that when I click submit, I want to use $sql to insert the company info in the firme table, and using $sql2 to insert what u see in that $sql2 query in id table.
    That is because I want to know, when I search a company, to see if that company is producer, what products has, if is a manufacturer, what products has, if is both, the same.
    Thank you for trying to help me.
     
    snowLee, Dec 10, 2009 IP
  18. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #18
    First delete the columns "id_categorie", "id_subcategorie", "id_ssubcategorie" and add this columns type of which set "text"

    id_categorie_producator, id_subcategorie_producator, id_ssubcategorie_producator, id_categorie_furnizor, id_subcategorie_furnizor, id_ssubcategorie_furnizor, id_categorie_concurent, id_subcategorie_concurent, id_ssubcategorie_concurent

    then change the names of <select> tag from "chk2" to "chk2[]", from "chk3" to "chk3[]"..., then delete the lines
    echo '<br /><br /><b>Categorii</b><br /><br />';
    everyewhere!! And set variables so
    $id_categorie_producator = implode(",",$_POST['chk2']);
    $id_subcategorie_producator = implode(",",$_POST['chk3']);
    $id_ssubcategorie_producator = implode(",",$_POST['chk4']);
    $id_categorie_furnizor = implode(",",$_POST['chk5']);
    $id_subcategorie_furnizor = implode(",",$_POST['chk6']);
    $id_ssubcategorie_furnizor = implode(",",$_POST['chk7']);
    $id_categorie_concurent = implode(",",$_POST['chk8']);
    $id_subcategorie_concurent = implode(",",$_POST['chk9']);
    $id_ssubcategorie_concurent = implode(",",$_POST['chk10']);

    And write this $sql2 query
    "INSERT INTO id(id_firma, id_categorie_producator, id_subcategorie_producator, id_ssubcategorie_producator, id_categorie_furnizor, id_subcategorie_furnizor, id_ssubcategorie_furnizor, id_categorie_concurent, id_subcategorie_concurent, id_ssubcategorie_concurent, producator, furnizor, concurent)
    VALUES('$nume', 'id_categorie_producator', 'id_subcategorie_producator', 'id_ssubcategorie_producator', 'id_categorie_furnizor', 'id_subcategorie_furnizor', 'id_ssubcategorie_furnizor', 'id_categorie_concurent', 'id_subcategorie_concurent', 'id_ssubcategorie_concurent', '$producator', '$furnizor', '$concurent')";
     
    s_ruben, Dec 10, 2009 IP