im triyng to figure out a problem for days and have some progress but im stuck with some checkbox page.
So the "project" is some kind of "online car stand" and im stuck in the insert car part.
I got the html and php for insert a car into the sql table.
Then after the car i have a link to insert extras of the car, like abs,cruise control, gps ...etc...
The Html is something like 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 is this one:
<html>
<head>
<meta charset="UTF-8">
<title>Inserir Automoveis</title>
</head>
<body>
<?php
include "connect.php";
$sql = "INSERT INTO extra (extra.id_carro,extra.id_lista_extra) SELECT carro.id_extras , ? FROM carro,lista_extra,extra ORDER BY 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 with that $sql is to get the last id from last car inserted on row cars and add 1 extra to him passed by the check box.
i have tried just with 1 box because i read that if a checkbox was unchecked pass "null"argument.
I tried already with diferent aproaches. My final goal is create a for cicle that creates the number of rows in table extra for each number of extra checked in my checkbox.
(i tried something like this but with no sucess)
$checkbox1 = $_POST['chk'];
if($_POST["Submit"]=="Submit"){
for ($i=0;$i<sizeof ($checkbox1)$i++){
$sql = "INSERT INTO extra (id_lista_extra) values('".$checkbox1[$i]."')";
mysql_query($sql) or die(mysql_error());
}
}
i got some php errors on that $i .
If someone can give me a hint i would appreciate.
Thanks
Aucun commentaire:
Enregistrer un commentaire