English 中文(简体)
如何防止在表格提交后重新制定?
原标题:How To Stop Variable From Resetting After Form Submit?

I m在项目上工作,I m 处理这一问题: 我有一个称为“类别”的变量,如果该类别无效或空洞,则将定为1类。 提交表格后,即第++类。 2. Okay,但第三人认为,它没有达到3。 我检查了发生的情况,我发现,每提交一次报告之后,美元就变成了1美元,因为第1条编码行文说,如果它无效或空洞,就会变成1美元。 1. 请允许我向各位展示一下我所说的话! 事先感谢你帮助!

session_start();

include_once( db.php );

$cat_SQL =  SELECT * FROM categories ORDER BY id ;
$cat_RESULT = mysql_query($cat_SQL, $conn);
$cat_ROWS = mysql_fetch_assoc($cat_RESULT);
$cat_ROWS_number = mysql_num_rows($cat_RESULT);

if (is_null($category) || empty($category)) {
    $category = 1;
}

if (isset($category)) {
    if ($category < $cat_ROWS_number) {
        $category = $category + 1; echo $category;
    }
}

因此,如果我每次重复页数,我就这样:

First time you enter the page: category is empty so it becomes 1 => $category = 1 After 1st SUBMIT $category = $category + 1 => $category = 2 After 2nd SUBMIT $category = $category + 1 => $category = 2 (still 2 instead of becoming 3) and so on... :( HOW CAN I STOP $category from become 1 each time the page reloads / submits, and become the new value instead (per session)?


因此,我最终在看到你的答复之前就设法这样做(不是包罗万象,而是高兴地看到我亲眼看到答案:) iii

if (!isset($_SESSION[ category ])) {
  $_SESSION[ category ] = 1;
  $category = $_SESSION[ category ];
}
else {
      if($_SESSION[ category ] < $cat_ROWS_number) {
          $_SESSION[ category ]++;
          $category = $_SESSION[ category ];
      }
}

然而,感谢大家的迅速答复!

最佳回答

这样做的一个办法是将美元类别列入届会变量。 在<代码>session_start/code>后,但在<代码>if (is_null($ category) >:

if(isset($_SESSION[ category ]))
    $category = $_SESSION[ category ];

之后,在<代码>美元 = 类别+1;之后,请:

$_SESSION[ category ] = $category;

这应当做到。

问题回答

或者在你把目前这一类别算入的表格中添加一个隐蔽的领域。





相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签