...

View Full Version : getting a php variable from a hidden input value , to use in mysql query



Juniper747
07-22-2012, 11:07 PM
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>
<div class="modal-body">
<p>One fine body!</p>
<input type="hidden" name="d_id" value="123" id="d_id"/>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>

So I want to add this php to the code:


$member_query = mysql_query("SELECT name, job FROM members WHERE (member_id='$d_id')");
while($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?

DrDOS
07-22-2012, 11:21 PM
Basically you're going to have to submit the data in a form, it will mean that a new page will be loaded, but you may need it to display the new data anyway. You may be able to send and receive the data by JSON or some other means, but how secure will that be vs post, and what liability would there be to reloading the page? Hardly any I should think, and the coding is very straightforward. Or maybe you could use the javascript .submit() function, but it will still reload the page.

Old Pedant
07-22-2012, 11:52 PM
??? Sounds to me more like a job for AJAX. Whether you would use JSON or not is up to you, though I would think if you are only going to send two values back to the HTML page (member_name and job, I am assuming?) I doubt you need JSON, at all.

But it also seems to me that is the member_id is in a hidden field, why not just also put the member_name and job in hidden fields? That is, get *ALL* the information when you create the page, rather than going and getting some of it later via AJAX?

Juniper747
07-23-2012, 12:09 AM
But wouldn't that basically be an iframe? Can't I simply use the value that I already obtained from the hidden input and convert it to a php variable?

Old Pedant
07-23-2012, 06:37 AM
But wouldn't that basically be an iframe? Can't I simply use the value that I already obtained from the hidden input and convert it to a php variable?

My head hurts.

You said this is a "modal dialog" and, by the HTML shown, I assume it is actually just a <div> that appears on top of the main page. Fine. Works for me.

But now, apparently, you want to go get *NEW CONTENT* for the <div> (you *did* mention "geElementById", no?) from PHP.

And I asked you: "WHY get NEW content from PHP? Why not simply PUT THE CONTENT THERE in the first place. *ALONG* with the d_id value???

I *assume* that the main page here, including the HTML you showed us, is actually a PHP page. No? So why bother running off when the modal dialog pops up, getting stuff from PHP, when you could have used PHP to put it on the page in the first place????

Juniper747
07-23-2012, 08:11 AM
Thanks for your replies... I was able to work it out.

It was a bit more complicated than I originally explained. I was working with a concatenated list, so the element id's had to all be different for each different modal window.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum