繁体   English   中英

在 2 PHP 中使用会话数组?

[英]Using Session Array in 2 PHP?

我有一个 PHP,其中我根据用户输入的用户名和密码列出了一些商店。它显示在下面的 php 中:

PHP

<?php  
include('includes/config.php');
 $upload = 'uploads/';
  session_start();
  if(isset($_POST["userid"],$_POST["pid"]))
{   
    $userid = $_POST["userid"];
    $pid = $_POST["pid"];

    $sql = "SELECT * FROM tbl_store WHERE username = '$userid' ";

    $result = mysqli_query($conn,$sql);
    $rowcount=mysqli_num_rows($result);
    $x = 1;
         echo "List of Stores for User".'  '."$userid".'<br/>';
        while($row = mysqli_fetch_array($result)){
            echo $x.'<br/>';

            //$row['store_code'].'<br/>'.'<br/>';
            echo "Store Code".'<br/>';
                        echo '<a href="jobs.php"/>'.$row['store_code'].'</a>'.'<br/>';
                        $_SESSION['$store_code'][] = $store_code;//is the format correct here for SESSION ARRAY??           



                        echo "Store Address".'<br/>';
                        echo $row['store_address'].'<br/>';
            echo "Store Chain".'<br/>';
                        echo $row['store_chain'].'<br/>';

                        echo "-----------------------------------------------------------------------------------------------------".'<br/>'.'<br/>';
            $x = $x +1;
        }

    }
    ?>

例如。

List of Store Code

1. 12345   //with hyperlink to another PHP

2. 123456 // with hyperlink to another 

3. 1234567 // with hyperlink


Now when I click  1.. Its is re-directed to another page.

Store Code: 12345

List of Jobs:

J1 

J2

J3

用于jobs.php的PHP,我想使用以前PHP中的SESSION数组根据单击的第一个超链接从数据库中获取详细信息。

<?php  
include('includes/config.php');
 $upload = 'uploads/';



    $sql = "SELECT * FROM tbl_job WHERE store_code = 'From the previous PHP' ";

    $result = mysqli_query($conn,$sql);
        $rowcount=mysqli_num_rows($result);
    $job = array();
    $client = array();
    $brand = array();
    $week = array();
    $imgCnt = 1;
    $x = 1;
    echo "LIST OF JOBS ".'<br/>'.'<br/>'; 
    while($row = mysqli_fetch_array($result)){
        echo $x.'<br/>';
        echo "Jobs".'<br/>';
         echo $row['jobs'].'<br/>'.'<br/>'; 
         // How to use Session array here to store 

         echo "Clients".'<br/>';
         echo $row['Client'].'<br/>'.'<br/>'; 


         echo "Brands".'<br/>';
         echo $row['Brand'].'<br/>'.'<br/>';

         echo "WEEK".'<br/>';
         echo $row['week'].'<br/>'.'<br/>';      


?>
    <form style = '<?php echo $imgCnt; ?>' id='uploadForm-<?php echo $imgCnt; ?>' action = '' method = 'POST'>
        <input type="file"  class="image<?php echo $imgCnt; ?>" name="img" onChange="readURL(this);" />
        <img id="blah" src="#" alt="your image" /><br/><br/>
        <input type='button' id = '<?php echo $imgCnt; ?>' class='uploadPicture<?php echo $imgCnt; ?> btn btn-primary' value = 'Upload'>
        <!-- <input type="button" value="upload" class="uploadPicture"  id="upload_btn<?php echo $imgCnt; ?>"/> -->
    </form>
    <form>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>

function readURL(input) {      
        if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            //$('#blah').attr('src', e.target.result).width(300).height(340);
             $(input).next('img').attr('src', e.target.result).width(300).height(340);
        };
        reader.readAsDataURL(input.files[0]);
    }

  }
</script>


<script type="text/javascript">
       $('.uploadPicture<?php echo $imgCnt; ?>').unbind().click( function(e) { 

        var file_data = $('.image<?php echo $imgCnt; ?>').prop('files')[0];   
        var form_data = new FormData();                  
        form_data.append('file', file_data);
        var edit_id = $(this).attr("id");
        $.ajax({
                url: "file.php",
                dataType: 'text',  // what to expect back from the PHP script, if anything
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function (result) {
                        alert(result)

                }
            });
        });
    </script>




                <?php
                echo "------------------------------------------------------------------------------------------------------".'<br/>';
         $x = $x + 1;
         $imgCnt++;
    }


?>

这是页面的屏幕截图。 在此处输入图片说明

现在,当我从 PHP 上传图像时,它应该移动到以该格式创建的文件夹和子文件夹中

客户/品牌/周/工作/Client_Brand_Week.jpg

你能帮我解决这个问题吗?

用于 file.php 的 PHP

<?php

    $imagePath = "uploads/";
    $temp = explode(".", $_FILES["file"]["name"]);

    $extension = end($temp);

    $filename = $_FILES["file"]["tmp_name"];
    echo "$filename";
    $time = time();
    move_uploaded_file($filename, $imagePath . $time . '.' . $extension);    
   echo "File Uploade";
   exit;
 ?>

在第一个 PHP 文件中:

echo "Store Code".'<br/>';
echo '<a href="jobs.php"/>'.$row['store_code'].'</a>'.'<br/>';
$_SESSION[$userid]['store_code'][] = $store_code;  //<-- this should work  
echo "Store Address".'<br/>';
echo $row['store_address'].'<br/>';
echo "Store Chain".'<br/>';
echo $row['store_chain'].'<br/>';
echo "-----------------------------------------------------------------------------------------------------".'<br/>'.'<br/>';
$x = $x +1;

但请注意,您尚未设置变量$store_code

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM