向数据库中的表中添加多倍数据时出错

问题描述 投票:-1回答:1

我的目标是打开一个字段,以添加与用户输入的数据一样多的数据,并批量保存此数据

   
<?php
	$connect = new mysqli('localhost','root','','not_impossible');
	

if(isset($_POST['submit'])){
	$adet =  $_POST['veri'];
	if($adet<=5 && $adet>0){
	echo <<<HTML
	
<form action='' method='POST' align='center'>
	<table align='center'>
		<tr style='border:none;background-color:black; color:white;'>
			<th>Yazılım İsmi</th>
			<th>Yazılımcı</th>
			<th>Cinsiyet</th>
			<th>Yazılım Fiyatı</th>
		</tr>
HTML;
$number = 0;
while($number<$adet){
echo <<<HTML
	<tr>
		<td><input type='text' name='x1' required></td>
		<td><input type='text' name='x2'></td>
		<td><input type='radio' value='Erkek' name='x3'>Erkek <input type='radio' value='Kadın' name='x3'>Kadın</td>
		<td><input type='text' name='x4'></td>
	</tr>						
			
HTML;
	$number++;			
			}
		echo "</table>";
	echo "<input type='submit' style='border:none;border-radius:2px;font-family:calibri;font-size:18px;width:150px;' name='ekle' value='Verileri Ekle'>".' '."<input type='reset' style='border:none;border-radius:2px;font-family:calibri;font-size:18px;width:150px;' value='Verileri Sil'>";
echo "</form>";

}
else{
	header('Refresh:2,url=index.php');
	echo "<h1>Girdiğiniz rakam 5 ten büyük olamaz</h1>";
}

}
else{
echo <<<HTML
<form action='' method='POST'>
<table>
<tr>
	<td>Kaç adet veri girmek istiyorsunuz ?</td>
	<td><input type='text' name='veri' required></td>
	<td><input type='submit' style='border:none;border-radius:2px;background-color:black;color:white;font-size:18px;font-family:calibri;'  name='submit'></td>
</tr>
</table>
</form>
HTML;
}
if(isset($_POST['ekle'])){
	$sql = $connect->prepare("insert into yazilim (yazilim_ismi,yazilimci,cinsiyet,yazilim_fiyat) values(?,?,?,?)");
	$sql->bind_param('sssi',$_POST['x1'],$_POST['x2'],$_POST['x3'],$_POST['x4']);
	$sql->execute();
	echo $sql->affected_rows.'Veriler Eklendi';
}
?>

我想使用form方法添加多个数据,但是数据没有正确添加到表中。我想将数据正确并顺序地添加到数据库中的表中,但是我无法弄清楚,并且我不完全了解复选框控制方法]

php html mysql mysqli prepared-statement
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.