1

以下のフォームを使用しています

<form method="get" action="daily_process.php">
Horse / Course / Time 

<input type='text' name='horse[]' />
<input type="text" name="course[]" />
<input type="text" name="time[]" />

<input type='text' name='horse[]' />
<input type="text" name="course[]" />
<input type="text" name="time[]" />

<input type='text' name='horse[]' />
<input type="text" name="course[]" />
<input type="text" name="time[]" />


<input name="submit" type="submit" />
</form>

以下のコードを使用してフォーム配列を処理し、印刷として出力します

<?php 
$horse = $_POST['horse'];
$course = $_POST['course'];
$time = $_POST['time'];

foreach( $horse as $key => $h ) {

if ($horse[$key] != "") {
  print "The horse is ".$h.", course is ".$course[$key].
        ", and time is ".$time[$key]." Thank you <br/>" ;
}}
?>

私の質問は、これらの結果を mysqli 用に準備するにはどうすればよいですか?

以下の例を StackOverflow で見ましたが、目的に合わせて編集するにはどうすればよいですか?

すなわち。$horse、$course、および $time をデータベースに保存する必要があります - table (horse,course, time) VALUES (?, ?, ?)

$query = "INSERT INTO table (link) VALUES (?)"; 
$stmt = $mysqli->prepare($query); 
foreach ($array as $one) { 
    $stmt ->bind_param("s", $one); 
    $stmt->execute(); 
} 
$stmt->close();
4

1 に答える 1

0
$query = "INSERT INTO table (horse,course,time) VALUES (?,?,?)"; 
$stmt = $mysqli->prepare($query); 

foreach( $horse as $key => $h ) {
    $stmt ->bind_param("sss", $h, $course[$key], $time[$key]); 
    $stmt->execute();
}

すべての値が文字列であると仮定します

PHP ドキュメントの bind_param の例は、複数の値をバインドする方法を示しています。

于 2013-07-21T08:22:05.963 に答える