Jul 22, 2020 04:53 PM
(This post was last modified: Jul 22, 2020 04:54 PM by blackcoder00.)
i have some trouble when i insert values into database the record repeats himself how can i avoid this problem guys
and thank alot
ps:i spend one week thinking and searching how to avoid this trouble without result
![[Image: Okfi57g.png]](https://i.imgur.com/Okfi57g.png)
![[Image: GBiqNLg.png]](https://i.imgur.com/GBiqNLg.png)
and thank alot
ps:i spend one week thinking and searching how to avoid this trouble without result
![[Image: Okfi57g.png]](https://i.imgur.com/Okfi57g.png)
PHP Code
<?php
$sql="SELECT name FROM ingredient";
$result=mysqli_query($conn,$sql);
/* if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}*/
echo"<select name='cars[]' id='cars' multiple >";
while($row=mysqli_fetch_assoc($result))
{
foreach ($row as $key => $okhrej) {
echo"<option value=".$okhrej.">".$okhrej."</option>";
}
}
echo"</select>";
$sql1="SELECT name FROM ingredient";
$result1=mysqli_query($conn,$sql1);
while($row1=mysqli_fetch_assoc($result1))
{
foreach ($row1 as $key1 => $okhrej1) {
echo "<input name='ingsave[]' >";
}
}
mysqli_close($conn);
![[Image: GBiqNLg.png]](https://i.imgur.com/GBiqNLg.png)
PHP Code
<?php
$selectop = $_POST['cars'];
$name = $_POST['nom'];
$prix = $_POST['prix'];
$prixn = $_POST['prix-neut'];
$savesplease = $_POST['ingsave'];
if(!empty($_POST['cars'])){
foreach ($selectop as $key ) {
foreach ($savesplease as $key1 ) {
mysqli_query($conn,"INSERT INTO coffe VALUES ('$key','$name','$prix','$prixn','$key1')");
}
}
echo "New record created successfully";
}
else {
echo "_error_: " . $sql . "<br>" . mysqli_error($conn);
}
Writeln('Give me a Target >');
![[Image: giphy.gif]](https://media.giphy.com/media/1n6CecAWjqgaa0fv0K/giphy.gif)


![[Image: fpZ5a5g.png]](https://i.imgur.com/fpZ5a5g.png)