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:
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.
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
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');
add this variables just after $producator = $_POST['producator']; $id_categorie = $_POST['chk2']; $id_subcategorie = $_POST['chk3']; $id_ssubcategorie = $_POST['chk4'];
Delete this lines echo '<br /><br /><b>Categorii</b><br /><br />'; echo '<form action="#" method="POST">'; Code (markup): everywhere in <select> tag.
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:
Delete the lines echo '<br /><br /><b>Categorii</b><br /><br />'; Code (markup): in <select> tags too.
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.
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.
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.
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')";