Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Pass variable from page to page

    Can anyone please tell me how should i pass the variable from login.php to display.php ? In my system, when users input their username, their display image will be shown in next page. but i just can't figure out how do i pass the input username from login.php to display.php although i read so many online solving. Can anyone please help or give me some hints perhaps ? Thank you so much for spending time to help me ^^

    login.php
    PHP Code:
        <?php
        
    include("connection.php");
            
            if (isset(
    $_POST["submitbtn"]))
        {    
            
            
    $name=$_POST["username"];
            
            
    $result=mysql_query("SELECT * FROM customerdetail WHERE customer_username = '$name' ");
            
            
    $num_row mysql_num_rows($result);
            
            if(
    $num_row==1)
            {
                
    $row=mysql_fetch_assoc($result);
                
                
    $checkname $row["customer_username"];
                
                if(
    $name == $checkname)
                {
                    
    $_SESSION["CID"] = $checkname;
        
    ?>
                
                    <script type="text/javascript">
                    
                    alert("User ID is correct!! Proceed to password Verification!!");
                    
                    window.location = "display.php";
                    </script>
                    
                    
        <?php
                
    }
                    else
                    {
        
    ?>
                    
                        <script type="text/javascript">
                    
                    alert("Login UnsuccessfuL!! Please Try again");
                    
                    window.location = "login.php";
                    </script>
                    
                    
        <?php
                        
    }
                        }
                else
                    {
        
    ?>
                    <script type="text/javascript">
                    
                    alert("Login UnsuccessfuL!! Please Try again");
                    
                    window.location = "login.php";
                    
                    </script>
        <?php
                        
    }
                    }
        
    ?>            
        <body>
            
            <div id="wrapper">
                
                <div id="header">
                    
                </div>
                
                <div id="content">
                    
                    <h1>Please Enter Your Username: </h1>
        <p>
        <form name = "frm1" method="post">
        <input type="text" name="username">
        </p>
        <p>
        <input type="submit" name="submitbtn" value="Login!">
        </form>
        </p>
                
                    </div>    
            </div>
        </body>
        </html>
    display.php
    PHP Code:
        <?php
            
    include("connection.php");
            
    $name=$_POST["username"];
            if(!isset(
    $name) || empty($name)){
        die(
    "Please select your image!");
            }else{
            
    $query mysql_query("SELECT * FROM customerdetail WHERE customer_username='$name'");
            
    $row mysql_fetch_array($query);
            
    $content $row["customer_face"];
            
    header('Content-type: image/jpg');
        echo 
    $content;
        }
        
    ?>
    Error:

    Code:
        Notice: Undefined index: username in C:\xampp\htdocs\MyProject3\display.php on line 5

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i know i should use $_SESSION and $_POST , $_GET, $_REQUEST for cookie and so on, but i just can't figure it out how it actually works ~

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    PHP Code:
            $name=$_POST["username"]; 
            if(!isset(
    $name) || empty($name)){ 
        die(
    "Please select your image!"); 
            }else{ 
    You can't refer to $_POST['username'] if it isn't set.

    PHP Code:
            if (!isset($name) || empty($name)) { 
                die(
    "Please select your image!"); 
            } else {
                
    // now we can refer to it..
                
    $name $_POST["username"]; 
    You could pass the value as a get, rather than post, value - although not recommended!

    PHP Code:
    window.location "display.php?name=$name";   // then refer to it in display.php..
    if (isset($_GET['name']) // etc.. 
    But you've already stored it as a session variable, so you can check and retrieve this value:

    PHP Code:
    if (isset($_SESSION["CID"])) { 
    BTW Use of the mysql library is deprecated/discouraged, although nobody seems to be getting this message .

    IF you are not sure, check the docs, including the comments.
    Last edited by AndrewGSW; 01-06-2013 at 09:24 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AndrewGSW View Post
    PHP Code:
            $name=$_POST["username"]; 
            if(!isset(
    $name) || empty($name)){ 
        die(
    "Please select your image!"); 
            }else{ 
    You can't refer to $_POST['username'] if it isn't set.

    PHP Code:
            if (!isset($name) || empty($name)) { 
                die(
    "Please select your image!"); 
            } else {
                
    // now we can refer to it..
                
    $name $_POST["username"]; 
    You could pass the value as a get, rather than post, value - although not recommended!

    PHP Code:
    window.location "display.php?name=$name";   // then refer to it in display.php..
    if (isset($_GET['name']) // etc.. 
    But you've already stored it as a session variable, so you can check and retrieve this value:

    PHP Code:
    if (isset($_SESSION["CID"])) { 
    BTW Use of the mysql library is deprecated/discouraged, although nobody seems to be getting this message .

    IF you are not sure, check the docs, including the comments.

    Thank you so much for helping. It finally pass the variable. but, there is another problem which the image just doesn't get displayed.

    Is it because my query error ? or this line got error ?
    PHP Code:
    header('Content-type: image/jpg'
    but when i change "image/jpg" to "customer/jpg", it started to download the display.php... so i think it's not the reason that the picture doesnt display. It just shows a icon which the picture is tease into half mean that cant be displayed.

    I tried the sample code below, it can work but not with my code...

    PHP Code:
     $storedid "3";

      
    $id = (int)$storedid;


    if(!isset(
    $id) || empty($id)){

    die(
    "Please select your image!");

    }else{


    $query mysql_query("SELECT * FROM tbl_images WHERE id='$id'");
    $row mysql_fetch_array($query);
    $content $row['image'];

    header('Content-type: image/jpg');
             echo 
    $content;


  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    I haven't done this before myself, but is the image stored as a BLOB in the database? Is the MIME-type (image/jpg) correct? Try image/jpeg - this is what I should be I believe.

    but when i change "image/jpg" to "customer/jpg"
    customer/jpg won't work; there are only specific MIME-types that you can use, you can't make them up .
    Last edited by AndrewGSW; 01-06-2013 at 10:14 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •