如何在一个会话中存储一定条件下的值[重复]。

问题描述 投票:1回答:1

**我想把$_POST中的数据存储到$_SESSION中,当用户点击提交按钮时,这些数据会在特定的条件下合适,我需要把经过认证的$_Session数组发送到另一个页面。但是,我的代码不能正常工作。谁能帮帮我吗:(**)

'''

session_start();
$errorFound = 0;

function test_input($data)
{
  $data = trim($data); 
  $data = stripslashes($data);
  $data = htmlspecialChars($data);
  return $data;
}

$cleanData_CUST_name = $_POST['cust']['cust[name]'];


if (isset($_POST['submit_booking'])){
    if (empty($_POST["cust[name]"])) {
        $nameErr = "Name is required";
        $errorFound++;
      } else {
            $name = test_input($_POST["cust[name]"]);
            if (!preg_match("/^[a-zA-Z ]*$/", $name)){
                $nameErr = "Only letters and whitespace are allowed.";
                $errorFound++;
       }if($errorFound ==0){
        $_SESSION['CUST'] =  $_POST['cust[name]']; 
       }
}

'''

php post session-variables
1个回答
0
投票
if (isset($_POST['submit_booking'])){
if (empty($_POST["cust[name]"])) {
    $nameErr = "Name is required";
    $errorFound++;
  } else {
        $name = test_input($_POST["cust[name]"]);
        if (!preg_match("/^[a-zA-Z ]*$/", $name)){
            $nameErr = "Only letters and whitespace are allowed.";
            $errorFound++;
   }if($errorFound ==0){
    $_SESSION['CUST'] =  $_POST['cust[name]']; 
   }
}
}

你缺少了一个分号来关闭 if (isset($_POST['submit_booking'])){

© www.soinside.com 2019 - 2024. All rights reserved.