猿问

如何在特定条件下在一个会话中存储值

**我想存储从 $_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]']; 

       }

}

'''


慕慕森
浏览 102回答 1
1回答

哆啦的时光机

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'])){
随时随地看视频慕课网APP
我要回答