www.webdeveloper.com
Results 1 to 11 of 11

Thread: Getting the value of a hidden input with PHP

  1. #1
    Join Date
    Apr 2014
    Posts
    42

    Getting the value of a hidden input with PHP

    Here is my input on the index.php page:

    Code:
    <form action='liked_button.php' action='GET'>
              <input type='hidden' class='hidden_image' name='hidden_image' value='<?php echo $image_info; ?>' >
    So how can I get that $image_info value to show in my liked_button.php?

    Code:
     $_GET['hidden_image'];
    Doesn't work and I have no idea what else to try.

    Any ideas?
    Last edited by jedaisoul; 06-04-2014 at 04:34 PM. Reason: typo

  2. #2
    Join Date
    Apr 2014
    Posts
    42
    edited code for that index.php:

    Code:
    <form action='liked_button.php' action='GET'>
    <input type='hidden' class='hidden_image' name='hidden_image' value='<?php echo $image_info; ?>' >

  3. #3
    Join Date
    Apr 2014
    Posts
    42
    When I click the submit button for that form, this is what shows up in my URL:

    Code:
    http://localhost/splindr_2.0/liked_button.php?like_button=Like&hidden_image=http%3A%2F%2Flocalhost%2Fsplindr_2.0%2Fphotos%2FV2R80FX4Tgn6mdE%2Fskullwatercolor.jpg

  4. #4
    Action = "get"? Do we SEE a problem here?!?

    METHOD="GET".

  5. #5
    Join Date
    Apr 2014
    Posts
    42
    just one of those things that slips by you when you've been working on the same thing all day I guess. Cheers!

  6. #6
    Join Date
    Apr 2014
    Posts
    42
    Actually, I just checked in my actual index.php page, and the method="GET", so I must've just mistakenly typed it in my post wrong. Still need to figure out why "GET" wont work.

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Try turning that field on so you can see if you have a value in it before the action.

  8. #8
    Join Date
    Apr 2014
    Posts
    42
    Yea I did a
    Code:
     vardump($image_info)
    and the value turned out to be exactly what I want it to be. I just need to "GET" the value of that input field now.

  9. #9
    Uhm, what does a echo '<pre>', print_r($_GET), '</pre>' show you?

    what does the actual output markup look like from that form? Are there invalid characters in your $image_info?

    I REALLY think we need to see a LOT more of your code to say what's going on.

  10. #10
    Join Date
    Apr 2014
    Posts
    42
    that's fine. was just trying to show the relevant part but I can paste the whole index.php here:

    Code:
    <!doctype html>
    
    <?php
        
        error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
       
        session_start();
    
    ?>
    
    <html>
    
    <head>
    
    <?php
    
    		include('header.php');
    
    ?>
      
    <!--<script>
    var username =   $('.liked_button').click(function()  {     
                        var username = $(this).data('username'), 
                        var image_info = $(this).data('image'); 
                           $.ajax ({type:"POST", url:'like_button.php', data:{user:username, image:image_info}, success:function() 
                          });   
                    }
    </script>-->
    
    <!--<script>
    $(document).ready(function()  {
        $(".like_button").click(function(){
             var like = $(this);
             $.ajax ({ url:"liked_button.php", type:"POST", data:{}, async:false, success:function(data) {
                 like.replaceWith("<button type='button' class='button_pressed'>Liked</button>")
             }});
        });
    });
    </script>-->
    
    <link type="text/css" rel="stylesheet" href="index.css">
    
    </head>
    
    <body>
    
    <?php
    //dispay the images that the users upload
    $conn = mysqli_connect("localhost","root","") or die ("No SQLI");
    		    
            mysqli_select_db($conn, "sample") or die ("No DB");
    
    $sqli = "SELECT * FROM `photos` ORDER BY `id` DESC";
    
    $result = mysqli_query($conn, $sqli) or die ("No query");
    
    while($row = mysqli_fetch_assoc($result))    
    
    {
        $username = $_SESSION['id'];
        
        $title = $row['title'];
        
        $description = $row['description'];
        
        $image_name = $row['image_name'];
        
        $random_directory = $row['random_direc'];
        
        $date = date('M/d/Y');
        
        $liked_img_loc = "";//prevent undefined index error
    
        $image_info = "http://localhost/splindr_2.0/photos/$random_directory/$image_name";
        //run query to get likes
        $sqli = "SELECT * FROM `likes` WHERE `liked_img_loc` = '$liked_img_loc' ";
        //query results
        $likes_result = mysqli_query($conn, $sqli) or die ("No query");
    
        $like_count = '0' ; $unlike_count = '0';
    
        while($likes_row = mysqli_fetch_assoc($likes_result))  { 
       
        if($likes_row['liked_unliked'] == 0)  { 
        
              $unlikeCount++; 
        
                   } else { 
        
              $like_count++; 
        
             }
        
        }
      
      }
    
    
    ?>
       
        <div id='contentWrapper'>
                 
                  <div class='photo'>
                      
                      <div class='actual_image'>
                        
                         <img src='<?php echo $image_info; ?>'>
                     
                      </div>          
                     
                      <div class='like_system'>
    
                                                <form action="liked_button.php" method='GET' name='like_form' class='form'>
                                                   
                                                   <img src="http://i.imgur.com/pMmYaYM.jpg" class="like_button button" name="like_button">
                                                   
                                                   <input type='hidden' name='hidden_image' class='hidden_image' value='<?php echo $image_info; ?>'>
                                                   
                                                   <input disabled type='text' name='total_likes' class='total_likes' value='0'>
                                               
                                                </form>
    
                                                   <a style='color: #2e4987;text-decoration:none' href="http://www.twitter.com/share?url=$image_info&hashtags=Splindr, CheckThisOut">
                                                    
                                                    <img class='twitter_button button' name='twitter_button' src="http://i.imgur.com/hKFKJoj.jpg"></a>
                                               
                                               <form action="comment_button.php" method="GET" name='comment_form' class='form'>
                                                   
                                                   <img class="show_comment button" name="show_comment" src="http://i.imgur.com/8azoFjh.jpg">
                                                   
                                                   <input disabled type='text' class='comment_count' name='comment_count' value='0'>
                                                   
                                                   <input type='hidden' name='hidden_comment' class='hidden_comment button' value='<?php echo $image_info; ?>'>
                                               
                                               </form>
                                                   
                                                   <img class="delete_button button" name="delete_button" src="http://i.imgur.com/wKZu2H1.jpg">
                      
                      </div> 
                            
                            <div class='info_wrapper'>
                               
                               <div class='info_header'>Title: <?php echo $title; ?> &nbsp By: <?php echo $username; ?> &nbsp Date: <?php echo $date; ?></div>
                                  
                                   <div class='description'><?php echo $description; ?></div>
                            
                            </div>
                            
                            <div class='comment_wrapper'>
                              
                              <div class='close_comment'>[close comments]</div>
                               
                               <div class='comment_box_wrapper'>
                                
                                <div class='comment_box'>
                                    
                                    <div class='profile_pic'><img src='https://i.imgur.com/1MkFvhU.png'></div>
                                    
                                    <div class='actual_comment'>Comment goes here...</div>
                                
                                </div>
                                
                                </div>
                                
                                <div class='post_comment'>
                                 
                                  &nbsp &nbsp <a style='color:#9b6bb4 ; text-decoration:none ; position:relative ; top:-5px'>Post Comment:</a>
                                              
                                              <input type='text' name='user_comment' class='user_comment'>
                                              
                                              <button type='button' class='comment_button' name='sumbit_comment'>Comment</button>
                               
                                </div>
                            
                            </div>
                      
                      </div>
                 
                  </div>
    
    <script>
    //hide comments
    $('.comment_wrapper').hide();
    //show comments
    $(document).ready(function()  {
      
      $('.show_comment').click(function()  {
       
        $('.comment_wrapper').show(500);
      
      });
    
    });
    //hide when 'close' is clicked
    $(document).ready(function()  {
      
      $('.close_comment').click(function() {
        
         $('.comment_wrapper').hide(500);
     
      });
    
    });
      
    </script>
    
    </body>
    
    </html>
    And here is the liked_button.php:

    Code:
    <?php
    
    	error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    	session_start();
    
    	$liked_img_loc = "";//prevent undefined index error
    	$liked_by = $_SESSION['id'];
    	$liked_unliked = '1';
    	$date = date('Y-m-d H:i:s');
    
    	$conn = mysqli_connect("localhost","root","") or die ("No SQLI");
    			mysqli_select_db($conn, "sample") or die ("No DB");
    
    	$likes_query = mysqli_query($conn, "SELECT * FROM `likes` WHERE `liked_img_loc` = '$liked_by'");
    
    	while($row = mysqli_fetch_assoc($likes_query))	{
    
    		$liked_unliked = $row['liked_unliked'];
    
    	}
    
    	if($row['liked_unliked'] == 1)	{//user has already liked
    		
    		echo "<script type='text/javascript'>alert('Sorry, but you can not like an image twice!');</script>";
    			
    			} else {//user hasn't already liked the image
    	
    	$sqli = "INSERT INTO `likes` (liked_img_loc, liked_by, liked_unliked, date) VALUES ('$liked_img_loc','$liked_by','$liked_unliked','$date')";
    
    	mysqli_query($conn, $sqli) or die ("No query");
    
    	header('location:index.php');
    
    	mysqli_close($conn);
    
    			}

  11. #11
    Join Date
    Apr 2014
    Posts
    42
    And the result of the vardump produces the info as a 'link'.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles