Results 1 to 3 of 3

Thread: getting a php variable from a hidden input value , to use in mysql query

  1. #1
    Join Date
    Apr 2012

    getting a php variable from a hidden input value , to use in mysql query

    I created a modal window, and was able to send an ID value to a hidden input field that opens up in the modal window. I need to transfer the value of that ID so that I can use it in a mysql query, so I can grab more info from the database...

    So here is the modal window that pops up:

    <div class="modal hide" id="myModal">
        <div class="modal-header">
        	<button type="button" class="close"data dismiss="modal">x</button>
        <div class="modal-body">
        	<p>One fine body!</p>
        	<input type="hidden" name="d_id" value="123" id="d_id"/>
        <div class="modal-footer">
        	<a href="#" class="btn btn-primary">Save changes</a>
    So I want to add this php to the code:

    PHP Code:
    $member_query mysql_query("SELECT name, job FROM members WHERE (member_id='$d_id')");
    $row mysql_fetch_array($member_query)){
    $member_name $row["name"];
    $member_job $row["job"];

    I was thinking to use some sort of javascript when the modal window loads like "onload getelementbyid"... so basically I need to somehow transfer the hidden input value (123), into a php variable $d_id. Is there an elegant way to do that?

  2. #2
    Join Date
    Sep 2011
    Bristol, England, United Kingdom
    There are a number of ways by which you could achieve this result. A simple method would be to submit the form onLoad and have PHP handle it as a $_GET or $_POST.

    Another method might be to use an AJAX/PHP request, which would require use of some simple HTTP request code in JavaScript along the lines of:

    window.addEventListener("load", send_to_php, false);
    function send_to_php()
        var value= document.getElementById("some_element").value;
        var xmlhttp = "";
        if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.onreadystatechange = function()
            if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
               // Handle HTTP response here.
        xmlhttp.open("GET", "some_page.php?some_param=" + somevalue, true);
    This tutorial on AJAX & PHP, while not directly related to your question, could be of help to you here since it explains fully how to send JavaScript data to PHP and uses MySQL to query a database.
    Last edited by George88; 07-22-2012 at 05:43 PM.

  3. #3
    Join Date
    Apr 2012
    Thanks very much!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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