脚本执行后如何保存用户在表单页面输入的数据?

 lucky燕子加加加 发布于 2023-02-12 03:56

我可以知道是否可以保存用户之前输入的表单中的数据?

这是表单文件:

    
    
    
                
        Data
        
    

    

    
Name:
DOB:
First Row:
Second Row:
Third Row:

这里是执行用户输入的表单数据的php.

 = $dob_date) { // this checks if the current month is the same as the user's month of birth and then checks if it is the user's birthday or if it is after it
        $age = $age;
    } else if ($month == $dob_month && $day < $dob_date) { //this checks if the current month is the user's month of birth and checks if it before the user's birthday
        $age = $age - 1;
    }

    //add all initial data into an matrix variable for easier access to them later
    //To access rowone use $rows[0][0], rowtwo $rows[1][0] ect.
    //The matrix is an array which contains multiple array. eg. 2-dimensional arrays
    //To get all the variables with $r1X simply retrieve the first array of the matrix eg $rows[0]
    $rows = array(array($_POST['rowone']), array($_POST['rowtwo']), array($_POST['rowthree']), array());

    //Similarities between row1 and row2 made me incoporate modulo value as an argument.
    function incmod($a, $m) {
        return ($a % $m) + 1;
    }

    //Population each row, with $populationCount number of elements, where each element is added with incmod(X, $mod)
    function populateRow($rowId, $populationCount, $mod) {
        //The global keyword is needed in order for the function to access the global variable.
        global $rows;
        $row = $rows[$rowId];
        while (sizeof($row) < $populationCount) {
            $rowInd = sizeof($row) - 1;
            $m = incmod($row[$rowInd], $mod);
            array_push($row, $m);
        }

        //Due to how php works with variables and references we need to set the row back into the global variable.
        $rows[$rowId] = $row;
    }

    //This function makes sure that the values allways are between 1 and 12.
    function bindToRange($v) {
        if ($v == 0)
            return 1;
        return ($v - 1) % 12 + 1;
    }

    //Population the first three rows
    populateRow(0, 7, 7);
    populateRow(1, 12, 12);
    populateRow(2, 12, 12);

    //Creating the forth row by nested forloops.
    //The first loop iterates over the entries in a row (in your example this would be the letters e.g r1a r1b ect)
    //The second (inner) loop iterates of the rows (in you example this would be the number you had in your variables.)
    //The sum over each of the three rows are added, then bound to 1-12 range, before being added to the forth row.
    for ($cId = 0; $cId < 7; $cId++) {
        $sum = 0;
        for ($rId = 0; $rId < 3; $rId++) {
            $sum += $rows[$rId][$cId];
        }
        array_push($rows[3], bindToRange($sum));
    }

    //Same as above, but for the last two remaining values. Should give a total of nine entries in the forth row.
    for ($cId = 7; $cId < 12; $cId++) {
        $sum = 0;
        for ($rId = 1; $rId < 3; $rId++) {
            $sum += $rows[$rId][$cId];
        }
        array_push($rows[3], bindToRange($sum));
    }

    function lower_than_2($var){
        return ($var > 1);
    }
    $cssClassName = "match";

    // array_count_values will count how many times each value is in the array
    $cssBase = array_count_values($rows[3]);
    // remove from array values that are lower than 2
    $cssBase = array_filter($cssBase, "lower_than_2");

    $cssNumber = array();
    $cssCounter = 1;
    // make $cssNumber be a mirror of $cssBase (same keys), but with serial values
    foreach ($cssBase as $key => $value) {
        $cssNumber[$key] = $cssCounter;
        $cssCounter++;
    }
    unset($cssCounter);
    // ------------------------------------------------

    ?>
    
    
        
            
            Result
            
        

        
            Customer Name: 
DOB: / /
Years Old \n"; if($rId < 3){ $row = $rows[$rId]; $rowSize = sizeof($row); for ($cId = 0; $cId < $rowSize; $cId++) { echo "\n"; } } else if($rId == 3){ $row = $rows[$rId]; $rowSize = sizeof($row); for ($cId = 0; $cId < $rowSize; $cId++) { echo ""; // close td echo $row[$cId]; echo "\n"; } } else if($rId == 4){ for ($cId = 0; $cId < 12; $cId++) { if($cId == (($age-1)%12)){ echo ''."\n"; } else { echo "\n"; } } } echo "\n"; } // ------------------------------------------------ ?>
" . $row[$cId] . "'. "$age Years Old" .'


Calculate Again

是否可以在count.php页面上添加一个保存按钮,该值将是表单页面中较早的用户键.保存按钮将回显"数据已保存",或者如果存在,它将在同一页面上回显"已存在的数据".如果是,我需要使用的方法是什么?我是全新的,因为我搜索谷歌,我无法找到我需要的答案.我已经在mysql中创建表来存储数据.

我想要存储的数据是出生日期,rowone,rowtwo和第三行.在mysql中创建表,dob为date,rowone,rowtwo和rowthree为varchar(255),id为int(11).

这是我的insertdata.php

  dob = $dob_date.'/'.$dob_month.'/'.$dob_year;
        }
    }

    $con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
    $sql="INSERT INTO profile (dob,rowone,rowtwo,rowthree) VALUES ('$_POST[dob]','$_POST[rowone]','$_POST[rowtwo]','$_POST[rowthree]')";

    if (!mysqli_query($con,$sql))
      {
      die('Error: ' . mysqli_error($con));
      }
    echo "1 record added";

    /* close connection */
    $mysqli->close();
    ?>

它显示如下错误:注意:未定义的索引:第18行的C:\ xampp\htdocs\mama\inc\insertdata.php中的dob

注意:未定义的索引:第18行的C:\ xampp\htdocs\mama\inc\insertdata.php中的rowone

注意:未定义的索引:第18行的C:\ xampp\htdocs\mama\inc\insertdata.php中的rowtwo

注意:未定义的索引:第18行的C:\ xampp\htdocs\mama\inc\insertdata.php中的rowthree 1添加了记录注意:未定义的变量:C:\ xampp\htdocs\mama\inc\insertdata.php中的mysqli在线27

致命错误:在第27行的C:\ xampp\htdocs\mama\inc\insertdata.php中的非对象上调用成员函数close()

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有