我在购物车项目中删除会话数组中的项目时遇到问题.以下代码应采用所选项目并将其从会话中删除.然而,最终结果与之前的会话相同,没有删除任何内容.我通过谷歌搜索看到了类似的问题,但还没有找到可行的解决方案.这是精简代码:
<?php
session_start();
$removeditem = $_GET['item']; // this identifies the item to be removed
unset($_SESSION['stuff'][$removeditem]); // "stuff" is the existing array in the session
?>
Run Code Online (Sandbox Code Playgroud)
以下是print_r为以下内容提供的内容(使用"7"作为已删除项目的示例):
$removeditem:
7
$_SESSION['stuff'] (before and after removal)
Array
(
[0] => 7
[1] => 24
[2] => 36
)
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西吗
我正在使用设置属性,setAttribute( Qt::WA_OpaquePaintEvent );是否可以取消设置该属性?还是我需要设置默认属性以使其恢复原样?谢谢。
我不知道还有什么可以称之为标题...我有一个访问某个MySQL数据库的PHP页面,从表中提取值,并将它们放在HTML表单中(POST方法 - PHP_SELF).然后,用户可以查看值,根据需要更改它们并提交它们.然后页面获取这些值并更新MySQL数据库.一切都很完美,除了当用户提交并且页面显示新的更新变量时,它仍然显示旧值.在新变量出现之前,用户被强制刷新页面.我认为PHP可能没有删除变量,所以我在脚本结束后取消设置所有存储的变量并且它仍然无法正常工作.我曾尝试在脚本启动之前安装睡眠定时器,但这也无效.我很感激任何建议.这是我的脚本仅供参考:
<html>
<body>
<?php
$sql = "SELECT * FROM lease";
$result = mysql_query($sql);
?>
<form id="lease_update" method="post" action="<?php echo htmlentities($PHP_SELF); ?>">
<table>
<tr>
<th>Account</th>
<th>Car Lease</th>
<th>Radio Lease</th>
<th>Misc. Charges</th>
</tr>
<?php
while($rows = mysql_fetch_array($result)){
?>
<tr>
<td><input type="text" name="account[]" value="<?php echo $rows['accnt']; ?>" /></td>
<td><input type="int" name="car_lease[]" value="<?php echo $rows['car']; ?>" /></td>
<td><input type="int" name="radio_lease[]" value="<?php echo $rows['radio']; ?>" /> </td>
<td><input type="int" name="misc_lease[]" value="<?php echo $rows['misc']; ?>" /></td>
<input type="hidden" name="lease_ID[]" value="<?php echo $rows['ID']; ?>" /> …Run Code Online (Sandbox Code Playgroud) 我有一个数组PHP:
$array = array("Linda","Chadwick","Bari","Angela","Marco");
Run Code Online (Sandbox Code Playgroud)
因此,
$array[0]="Linda"
$array[1]="Chadwick"
$array[2]="Bari"
$array[3]="Angela"
$array[4]="Marco"
Run Code Online (Sandbox Code Playgroud)
我想删除具有字符串长度的名称<=4.
这样,键就被调整了.
$array[0]="Linda"
$array[1]="Chadwick"
$array[2]="Angela"
$array[3]="Marco"
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用unset函数从php数组中删除特定元素。问题是,当我使用var_dump数组时,它会显示所有索引(不好),但是如果我尝试使用var_dump特定的索引,PHP会发出警告(很好)。
$a = [
'unset_me',
'leave_me',
'whatever',
];
unset($a['unset_me']);
var_dump($a);
/**
array(3) {
[0]=>
string(8) "unset_me"
[1]=>
string(8) "leave_me"
[2]=>
string(8) "whatever
*/
var_dump($a['unset_me']); // Undefined index: unset_me
Run Code Online (Sandbox Code Playgroud)
问题是为什么php会像这样,以及如何正确删除索引?
我的代码有问题.
我试图在正确的列上搜索一些可以帮助我的答案,但我没有找到.
这是我的插入代码:
<?php
if(isset($_POST['**'])) {
$set_time_out = 60;
setcookie("***", "username", time()+60, "admin");
}
?>
Run Code Online (Sandbox Code Playgroud)
现在,我未设置的代码是:
if(isset($_GET['**']) == '***') {
unset($_COOKIE['***']);
}
Run Code Online (Sandbox Code Playgroud)
当我进入"获取"链接时,什么也没发生.
cookie仍然存在.
请帮忙 :)
编辑
登录代码是..
<?php
if(isset($_POST['*'])) {
$set_time_out = 60;
setcookie('***', '**', time()+60, 'admin/');
}
?>
我的"注销"代码是:
`
if(!$_COOKIE['***']) {
echo "<meta http-equiv=\"refresh\" content=\"0;url=../login.php\">";
}
if(isset($_GET['**']) == '******') {
setcookie('***', '', time()-60, 'admin/');
}
Run Code Online (Sandbox Code Playgroud)
?>`
unset ×6
php ×5
arrays ×2
array-unset ×1
attributes ×1
cart ×1
cookies ×1
forms ×1
html ×1
mysql ×1
qt ×1
session ×1
setattribute ×1
strlen ×1
variables ×1