0

ユーザー入力から 1 つのデータベースに保存される情報を 5 つのテーブルに取得しようとしています。ポップアップするエラーはありませんが、データは DB に保存されません。サンプル コードまたは型指定されたソリューションは素晴らしいものです。ありがとう。

これまでのコードは次のとおりです。配列は別のページで定義されています。

$array = array("example");
$random = $array;
shuffle($random);

HTML:

<tr>
<form action="Voting_action.php" method="post">
<td><input type="image" value="<?php echo $img;?>" /> 
<input type="submit"class="buttontable1" value="<?php echo array_pop($random);?>" name="name"/></td>
<td><input type="image" value="<?php echo $img;?>" />
<input type="submit" class="buttontable2" value="<?php echo array_pop($random2);?>" name="name2" /></td>
</form>
</tr>

<tr>
<form action="Voting_action.php" method="post">
<td><input type="image" value="<?php echo $img;?>" />
<input type="submit" class="buttontable1" value="<?php echo array_pop($random3);?>" name="name3"/></td>
<td><input type="image" value="<?php echo $img;?>" />
<input type="submit" class="buttontable2" value="<?php echo array_pop($random4);?>" name="name4" /></td>
</form>
</tr>

<tr>
<form action="Voting_action.php" method="post">
<td><input type="image" value="<?php echo $img;?>" />
<input type="submit" class="buttontable1" value="<?php echo array_pop($random);?>" name="name"/></td>
<td><input type="image" value="<?php echo $img;?>" />
<input type="submit" class="buttontable2" value="<?php echo array_pop($random5);?>" name="name5" /></td>
</form>
</tr>

これは、他のチュートリアルやフォーラムの助けを借りて、これまでに作成した PHP mysqli コードです。

<?php
include('Voting.php');
$server = '';
$dbname= '';
$username = '';
$password = '';


$link = new mysqli($server, $username, $password, $dbname);

if (mysqli_connect_error()) {
header('Location: /errordocs/500.php');
exit;
}

$link->autocommit(FALSE);


$sql = "INSERT INTO table (name) VALUES (?)";

if ($stmt = $link->prepare($sql)) {
  $stmt->bind_param("sssss", $array);
  $stmt->execute();

$firstinsert = $stmt->affected_rows;
 }
$stmt->close;

$newid = $link->insert_id;

$sql = "INSERT INTO table(name2) VALUES (?)";

if ($stmt = $link->prepare($sql)) {
  $stmt->bind_param("ssi", $array2);
  $stmt->execute();

$secondinsert = $stmt->affected_rows;
 }
$stmt->close;

$newid = $link->insert_id;

$sql = "INSERT INTO table(name3) VALUES (?)";

if ($stmt = $link->prepare($sql)) {
  $stmt->bind_param("ssi", $array3);
  $stmt->execute();


$thirdinsert = $stmt->affected_rows;
 }
$stmt->close;

$newid = $link->insert_id;


$sql = "INSERT INTO table(name4) VALUES (?)";

if ($stmt = $link->prepare($sql)) {
  $stmt->bind_param("ssi", $array4);
  $stmt->execute();

$fourthinsert = $stmt->affected_rows;
 }
$stmt->close;

$newid = $link->insert_id;

$sql = "INSERT INTO table(name5) VALUES (?)";

if ($stmt = $link->prepare($sql)) {
  $stmt->bind_param("ssi", $array5);
  $stmt->execute();


$fifthinsert = $stmt->affected_rows;
 }
$stmt->close;


if (($firstinsert == 1) && ($secondinsert == 1) && ($thirdinsert == 1) && ($fourthinsert == 1) && ($fifthinsert == 1)) {

$link->commit();
$link->autocommit(TRUE);
  return 1;
 } else {
$link->rollback();
$link->autocommit(TRUE);
  return 0;
 }
?>

少し早いですがお礼を!

4

0 に答える 0