html - checkbox value to mysql/php -
im triyng figure out problem days , have progress im stuck checkbox page.
so "project" kind of "online car stand" , im stuck in insert car part.
i got html , php insert car sql table.
then after car have link insert extras of car, abs,cruise control, gps ...etc...
the html this:
<?php include "verifica.php"; ?> <html> <head> <link rel="stylesheet" href="styles.css"> <title> stand automovel </title> </head> <body> <form action="extras.php" method="post"> <p class="style2"style2"> extras: <div class="style2"> <input type="checkbox" name="chk" value="1">gps<br> <input type="checkbox" name="chk" value="2">abs<br> <input type="checkbox" name="chk" value="3">computador de bordo<br> <input type="checkbox" name="chk" value="4">ar condicionado<br> </div> <p> </p> <p><input type=submit value="submeter"> <input type=reset value="limpar"> </p> <p> </p> </form> </body>
the php page code one:
<html> <head> <meta charset="utf-8"> <title>inserir automoveis</title> </head> <body> <?php include "connect.php"; $sql = "insert (extra.id_carro,extra.id_lista_extra) select carro.id_extras , ? carro,lista_extra,extra order carro.id_carro desc limit 1"; if($teste= $mysqli->prepare($sql)) { $teste->bind_param("s",$_request["extra.id_lista_extra"]); $teste->execute(); if ($teste>affected_rows == -1) { echo $print; echo "<p>". $mysqli->error. "</p>"; } else { echo "<sp>carro inserido com sucesso!</p>"; } } ?>
the goal $sql last id last car inserted on row cars , add 1 him passed check box.
i have tried 1 box because read if checkbox unchecked pass "null"argument.
i tried diferent aproaches. final goal create cicle creates number of rows in table each number of checked in checkbox.
(i tried no sucess)
$checkbox1 = $_post['chk']; if($_post["submit"]=="submit"){ ($i=0;$i<sizeof ($checkbox1)$i++){ $sql = "insert (id_lista_extra) values('".$checkbox1[$i]."')"; mysql_query($sql) or die(mysql_error()); } }
i got php errors on $i .
if can give me hint appreciate.
thanks
here example have change names inside these $_post
variables change html checkbox names have []
after them. e.g
<input type="checkbox" name="chk[]" value="1">gps<br> <input type="checkbox" name="chk[]" value="2">abs<br> $cat_array = array(); if(isset($_post['chk'])){ if(is_array($_post['chk'])) { foreach($_post['chk'] $value){ array_push($cat_array, $value); } }else{ $value = $_post['chk']; array_push($cat_array, $value); } }
now these values in array. please them, loop through them, call them there indexes, etc..
Comments
Post a Comment