3 Replies - 2430 Views - Last Post: 30 October 2010 - 06:02 PM Rate Topic: -----

#1 Guest_Silva*


Reputation:

Passing record id to a new window

Posted 30 October 2010 - 08:56 AM

Hi all,

I'm using a select query to display data, I have an edit icon next to each record and I need to know how to pass the id into a new window so I can populate the edit form. How do I pass the value?
Is This A Good Question/Topic? 0

Replies To: Passing record id to a new window

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4444
  • View blog
  • Posts: 12,318
  • Joined: 18-April 07

Re: Passing record id to a new window

Posted 30 October 2010 - 10:49 AM

Well the simplest way would be to construct a URL for the icon and make one of the parameters the ID of the record. For instance, when you display the records, you construct a URL for each like.. echo "<a href=\"otherwindow.php?id=$recID\" target=\"_blank\"><img src=\"icon.gif\"/></a>";. Notice we pass along the record id as a parameter to our other page. When they click the icon, which is now a link, it will pass along the ID to the other page when the window opens.

So you would have this URL building PHP line in your loop where you are displaying records. Hope you get what I mean here. :)

P.S. Otherwindow.php would then verify the incoming ID (since it is passed by get), make sure the user has access to view that record and if so, then use it to query the record and fill in the form with whatever data you want.

This post has been edited by Martyr2: 30 October 2010 - 10:51 AM

Was This Post Helpful? 1
  • +
  • -

#3 Guest_Silva*


Reputation:

Re: Passing record id to a new window

Posted 30 October 2010 - 11:31 AM

View PostMartyr2, on 30 October 2010 - 09:49 AM, said:

Well the simplest way would be to construct a URL for the icon and make one of the parameters the ID of the record. For instance, when you display the records, you construct a URL for each like.. echo "<a href=\"otherwindow.php?id=$recID\" target=\"_blank\"><img src=\"icon.gif\"/></a>";. Notice we pass along the record id as a parameter to our other page. When they click the icon, which is now a link, it will pass along the ID to the other page when the window opens.

So you would have this URL building PHP line in your loop where you are displaying records. Hope you get what I mean here. :)

P.S. Otherwindow.php would then verify the incoming ID (since it is passed by get), make sure the user has access to view that record and if so, then use it to query the record and fill in the form with whatever data you want.


Hmmmm, I don't really understand it that way. How would the other form verify it?

I started trying to do it via post and a form, here is what I've got:

<form action=\"editrecord.php\" method=\"post\" onsubmit=\"window.open('editrecord.php?vehicle_id=" . $dbfield['vehicle_id'] . "', 'Edit Record', 'toolbar=no,width=740,height=450'); return false;\"><input type=\"image\" src=\"images/edit.png\" name=\"edit[" . $db_field['vehicle_id'] . "]\"></form>

<form action=\"delete.php\" method=\"post\">
<input type=\"image\" src=\"images/delete32.png\" name=\"delete[]\">This will delete " . $db_field['vehicle_id'] . "</form>


Then some ofeditrecord.php

<form id="editrecord" name="editrecord" method="post" action="editrecord-exec.php">
<?php
$recordid=$_POST['vehicle_id'];
print $recordid;
$result=mysql_query("SELECT * FROM cars WHERE vehicle_id='$recordid'");

$data=mysql_fetch_array($result);

?>
  <table width="700" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td>Vehicle Make </td>
      <td><input name="vmake" type="text" class="textfield" id="vmake" value="<? print $data['vehicle_make'] ?>"/></td>


Not working, stumped
Was This Post Helpful? 0

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3105
  • View blog
  • Posts: 10,905
  • Joined: 08-August 08

Re: Passing record id to a new window

Posted 30 October 2010 - 06:02 PM

Why not just include the next page instead of redirecting to it? Then you don't need to pass any variables to it because you've already got them!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1