html表单复选框隐藏,带复选框的HTML表单元素

我有一些PHP显示如下的HTML表单: Mdxgz.png 然后在按下更新按钮时更新表中的信息。带复选框的HTML表单元素

我的问题是删除选项。任何时候我打的更新按钮,信息更新成功,但我得到了delete语句此错误消息: CSg2g.png

下面是代码:// 信息连接到数据库的心愿$ =服务器名“.COM”; $ dbusername =“”; $ password =“”; $ dbname =“”;

try {

// To connect to the database please

$conn = new mysqli($servername, $dbusername, $password, $dbname);

if ($conn->connect_error) {

die('Connect Error (' . $conn->connect_errno . ') '

. $conn->connect_error);

}

echo "Please click here to add creatures to your wishlist.";

if(isset($_POST['submit'])){

$ids = $_POST['ids'];

// Prepare and bind the udpate statement

$sql2 = "UPDATE Wishlists SET Picture = ?, Stage = ?, Gender = ?, Frozen = ?, Notes= ? WHERE ID = ?";

$stmt2 = $conn->prepare($sql2);

$stmt2->bind_param('sssssi', $picture, $stage, $gender, $frozen, $notes, $id);

foreach($ids as $id){

$stagecode = $id . "stage";

$gendercode = $id . "gender";

$frozencode = $id . "frozen";

$notescode = $id . "notes";

$namecode = $id . "creature";

$stage = $_POST[$stagecode];

$Stage = $stage;

$gender = $_POST[$gendercode];

$frozen = $_POST[$frozencode];

$notes = $_POST[$notescode];

$name = $_POST[$namecode];

$sql1 = 'SELECT * FROM Creatures WHERE Name = "' . $name . '"';

$result = mysqli_query($conn, $sql1);

$row = $result->fetch_assoc();

$picture = $row["$stage"];

$stmt2->execute();

}

$theCount = 0;

foreach($_POST['delete'] as $selected){

$sql = "DELETE FROM Wishlists WHERE ID = ?";

$stmt = $conn->prepare($sql);

$stmt->bind_param('i', $selected);

$stmt->execute();

$theCount++;

}

echo "Your wishlist has been updated, and" .$theCount. " creature(s) has/have been removed from your wishlist.
Please click here to return to the edit page.";

} else {

// Get current user's username

$current_user = wp_get_current_user();

$username = $current_user->user_login;

$theDeleteCount = 0;

// Just display the form

$sql = 'SELECT Creature, Picture, Stage, Gender, Frozen, ID FROM Wishlists WHERE Username = "' . $username . '"';

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {

echo '

' .

'

' .

'

' .

'

Creature' .

'

Stage' .

'

Gender' .

'

Frozen' .

'

';

while($row = $result->fetch_assoc()) {

$creature = $row["Creature"];

$id = $row["ID"];

$picture = $row["Picture"];

$stage = $row["Stage"];

echo '' .

'' .

'

' .

'

'%20.%20%24picture%20.%20'' .

'

' . $creature . '' .

'

' .

'' . $stage . '' .

'Stage1(Egg)' .

'Stage2' .

'Stage3' .

'Stage4' .

'

' .

'

' .

'' . $row["Gender"] . '' .

'Unspecified' .

'Female' .

'Male' .

'

' .

'

' .

'' . $row["Frozen"] . '' .

'Unspecified' .

'Yes' .

'No' .

'

' .

'

' .

'

' .

'

Notes: ' .

'

' . 'Delete
' . '' .

'

';

}

echo '

';

} else {

echo "
You have no creatures in your wishlist.";

}

}

} catch (mysqli_sql_exception $e) {

throw $e;

}

// Close the connection to the database

$conn->close();

如果你能帮我找到什么是错的,我传递给在foreach()语句的信息:

foreach($_POST['delete'] as $selected){

我将永远感激。任何想法都有帮助

我已经尝试了很多东西,其中很多都是在stackoverflow上找到的。我想我可能错过了一些小小的和/或愚蠢的东西。我有另一个页面运行的复选框表单,工作得很好。

谢谢你,祝你有美好的一天!

2016-07-26

TurtleBo

+0

很可能会出现POST阵列的所有表单提交中没有'delete'所以你应该大概在循环之前测试一下 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值