我正在尝试从一个数据库中将信息保存到用户输入的5个表中。 弹出没有错误,但数据不会保存到数据库。任何示例代码或键入的解决方案都会很棒。感谢。
到目前为止,这是我的代码: 数组在不同的页面上定义。
$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;
}
?>
提前感谢!