我见过很多像我这样的人在这个论坛上发布过这个问题。
我无法从任何这些例子中解决我自己的问题。
例如,下面的代码来自名为review.php的页面:
<?php
error_reporting(E_ALL);
echo "DEBUG POST DATA: <pre>".print_r($_POST, 1)."</pre>";
if(isset($_POST['employeename']))
$employeename = $_POST['employeename'];
if(isset($_POST['email']))
$email = $_POST['email'];
if(isset($_POST['ttitle']))
$ttitle = $_POST['ttitle'];
$rowIDs = $_POST['rowIDs'];
$row2IDs = $_POST['row2IDs'];
echo $employeename .'<br>';
echo $ttitle .'<br> <hr width=400 align=left>';
$rowIDs = $_POST['rowIDs'];
foreach ($rowIDs as $id) {
$sourcename = $_POST['sourcename' . $id];
$sourceaddress = $_POST['sourceaddress' . $id];
$income = $_POST['income' . $id];
echo 'Name: '. $sourcename . '<br />';
echo 'Address: '. $sourceaddress . '<br />';
echo 'Income: '. $income . '<br /><br>';
}
foreach ($row2IDs as $id) {
$spousename = $_POST['spousename' . $id];
$spouseAddress = $_POST['spouseAddress' . $id];
$spouseIncome = $_POST['spouseIncome' . $id];
echo 'Name: '. $spousename . '<br />';
echo 'Address: '. $spouseAddress . '<br />';
echo 'spouseIncome: '. $spouseIncome . '<br /><br>';
echo 'Your email: '. $email . '<br /><br>';
}
?>
<body>
<form action='final.php' method = 'POST'>
<input type="hidden" name="employeename" value="<?php echo $employeename; ?>">
<input type="hidden" name="ttitle" value="<?php echo $ttitle; ?>">
<input type="hidden" name="sourcename[]" value="<?php echo $_POST['sourcename' . $id]; ?>">
<input type="hidden" name="sourceaddress[]" value="<?php echo $_POST['sourceaddress' . $id]; ?>">
<input type="hidden" name="income[]" value="<?php echo $_POST['income' . $id]; ?>">
<input type="hidden" name="spousename[]" value="<?php echo $_POST['spousename' . $id]; ?>">
<input type="hidden" name="spouseAddress[]" value="<?php echo $_POST['spouseAddress' . $id]; ?>">
<input type="hidden" name="spouseIncome[]" value="<?php echo $_POST['spouseIncome' . $id]; ?>">
<a href="javascript:history.go(-1)">Return to correct changes</a> <input type="submit" value="submit" />
</form>
</body>
当我运行它时,我得到: 注意:第70行的C:\ xampp \ htdocs \ folder \ forms \ final.php中的数组到字符串转换
错误指向此行:
if(mysqli_stmt_execute($ sth)){...
是以下插入语句的一部分:
$sql = 'INSERT INTO `mydb`.`wp_mytable` ( `employeeID`'
. ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseincome` )'
. ' VALUES ( ? , ? , ? , ? , ? , ? , ? )';
if( $sth = mysqli_prepare($conn,$sql) ) {
mysqli_stmt_bind_param($sth,'sssssss'
,$last_id
,$_POST["sourcename"]
,$_POST["sourceaddress"]
,$_POST["income"]
,$_POST["spousename"]
,$_POST["spouseAddress"]
,$_POST["spouseIncome"]
);
我也知道我需要在这些字段上做一个FOR循环,就像下面这个我以隐藏形式传递的数组。
<input type="hidden" name="sourcename[]" value="<?php echo $_POST['sourcename' . $id]; ?>">
如何在review.php上的这些隐藏表单字段中加入foreach循环,以便用户可以存储尽可能多的行而不会妨碍这些错误?
谢谢