Current location: Hot Scripts Forums » Programming Languages » PHP » Passing the ID value from one page to the other


Passing the ID value from one page to the other

Reply
  #1 (permalink)  
Old 07-12-05, 10:39 PM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Passing the ID value from one page to the other

i wan to display rows from my table with an additional column call edit. users will be able to edit the reports that they reported. for each row that is displayed, a radio button is displayed with the value of the reportid. i linked this page to another page where by i need to get the reportid of the radio button selected on the previous page.

<?
$query = "SELECT ReportID, AircraftType, AircraftTailNo, AirFrameHours, ServicingType, DefectInfo FROM Report WHERE UserID='$UserID'";
$result = mysql_query($query)
or die ("couldn't execute query.");

while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<tr>
<td>$row[ReportID]</td>
<td>$row[AircraftType]</td>
<td>$row[AircraftTailNo]</td>
<td>$row[AirFrameHours]</td>
<td>$row[ServicingType]</td>
<td>$row[DefectInfo]</td>
<td><input type=\"radio\" name=\"Edit\" value=\"'$row[ReportID]'\"></td>
</tr>";
}
?>

i know its something to do with $_GET, but i m not really sure about it. mind giving a few pointers or give a a really brief sample code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-12-05, 11:34 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by phplearner
i wan to display rows from my table with an additional column call edit. users will be able to edit the reports that they reported. for each row that is displayed, a radio button is displayed with the value of the reportid. i linked this page to another page where by i need to get the reportid of the radio button selected on the previous page.

<?
$query = "SELECT ReportID, AircraftType, AircraftTailNo, AirFrameHours, ServicingType, DefectInfo FROM Report WHERE UserID='$UserID'";
$result = mysql_query($query)
or die ("couldn't execute query.");

while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<tr>
<td>$row[ReportID]</td>
<td>$row[AircraftType]</td>
<td>$row[AircraftTailNo]</td>
<td>$row[AirFrameHours]</td>
<td>$row[ServicingType]</td>
<td>$row[DefectInfo]</td>
<td><input type=\"radio\" name=\"Edit\" value=\"'$row[ReportID]'\"></td>
</tr>";
}
?>

i know its something to do with $_GET, but i m not really sure about it. mind giving a few pointers or give a a really brief sample code.
Just grab the vars from the $_REQUEST superglobal:

$ReportID = $_REQUEST['Edit'];

$ReportID will hold the value of whichever radio button was checked.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-13-05, 12:56 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
thx alot! i will try it out right away.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-13-05, 01:02 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
erm.. i linked the form to another page to test whether the value of the selected radio button is stored or not. i juz did a simple echo out but there is an error.

Notice: Undefined variable: ReportID in c:\inetpub\wwwroot\SIP\first\asd.php on line 3
= Edit

<?php

echo "$ReportID = $_REQUEST[Edit]";


?>

does that mean i cant get the value?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-13-05, 04:35 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
why are you using extract() in your first code? extract makes variables the same name as the column name and then you echo $row['column']; ??

you cant echo a variable = value string, either do

PHP Code:

 echo $ReportID $_REQUEST['Edit']; 

or

PHP Code:

 echo $_REQUEST['Edit']; 

You cant name a key like you have in REQUEST, it has to be in quotes

I would suggest you start here:
http://ie2.php.net/manual/en/tutorial.php

The PHP Manual is very good..

The purpose of GET or POST or REQUEST are listed under the variables (predefined I think) in the manual
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-14-05, 09:26 PM
rrwh rrwh is offline
New Member
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
The thing you are missing is that you probably need a form so you can pass the value to your new page


You may want to wrap the whole table up in a form so you can post the value to the next page.

<form action=\"newpage.php\" method=\"post\">
<table>

//insert your original code here

Quote:
extract($row);
echo "<tr>
<td>$row[ReportID]</td>
<td>$row[AircraftType]</td>
<td>$row[AircraftTailNo]</td>
<td>$row[AirFrameHours]</td>
<td>$row[ServicingType]</td>
<td>$row[DefectInfo]</td>
<td>Edit this record <input type=\"radio\" name=\"Edit\" value=\"'$row[ReportID]'\"></td>
</tr>";
</table>
<input type=\"radio\" name=\"Edit\" value=\"'$row[ReportID]'\">
</form>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-14-05, 09:37 PM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
thx for the replies guys... sorry my codes are taken from some php beginner book. i juz started so pls bear with mi =)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-15-05, 12:34 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
i did the way u guys suggested but when i echo out the radio button value, it shows Edit instead of the report id value like 1 , 2 etc..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-15-05, 04:00 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$ReportID $_REQUEST['Edit']; 

echo 
$ReportID
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Passing a variable to another page tapir PHP 8 02-16-05 06:38 PM
Passing text vs numeric data as ID from one ASP page to another arobbo61 ASP 7 09-24-04 02:02 AM
page browsing problem mivec PHP 3 04-17-04 04:43 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 07:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.