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 03: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
    1,904
    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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.19191 seconds
  • Memory Usage 2,963KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (7)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (11)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (11)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates