Jump to content

Just a little help needed on hidden inputs in forms


wattsup88

Recommended Posts

Hello all,

Of course im a noob or i wouldn't be asking for help so bear with me... I have been having trouble passing global variables page to page... My goal is to be able to pass an id number from one page to the next... here is the code...

First the form code...

//****query dispayed****//

while ($row = mysql_fetch_array($result))
  {
        $jbc = $row['jbcategory'];
        $jbt = $row['jbtitle'];
        $jbs = $row['jbsalary'];
$jbst = $row['jbstate'];
$id = $row['id'];

//alternating colors code

$row_color = ($row_count % 2) ? $color1 : $color2;

//alternating colors code

    print "<tr>
<td width=\"5\" bgcolor=\"990101\" nowrap>\n";

print "<td width=\"200\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbt)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbc)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbs)."</td>";
print "<td width=\"50\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbst)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap><input type=\"hidden\" value=\"$id\" name=\"$id\"><input type=\"submit\" value=\"View Job\"></td>";
print "<td width=\"5\" bgcolor=\"990101\" nowrap>\n";
    print "</tr>\n";
$row_count++;
  }
print "</table>\n";
//****query dispayed****//




Now... the result page

<?php

$value = $_POST['$id'];

$result = mysql_query("SELECT * FROM jobs WHERE id = '$value'");



//****query dispayed****//

while ($row = mysql_fetch_array($result))

  {

        $jbc = $row['jbcategory'];
        $jbt = $row['jbtitle'];
        $jbs = $row['jbsalary'];
$jbst = $row['jbstate'];
$jbdesc = $row['jbdesc'];
$jbqual = $row['jbqualifications'];
$jbco = $row['jbcompany'];
$jbcity = $row['jbcity'];
$jbstatus = $row['jbstatus'];


print "<td width=\"60\" bgcolor=\"990101\" rowspan=\"8\">\n";
print "<tr><td><strong>Job Title: </strong><br/>".stripslashes($jbt)."</td></tr>";
print "<tr><td><strong>Job Category: </strong><br/> ".stripslashes($jbc)."</td></tr>";
print "<tr><td><strong>Salary: </strong><br/> ".stripslashes($jbs)."</td></tr>";
print "<tr><td><strong>Location: </strong><br/>$jbcity, $jbst</td></tr>";
print "<tr><td><strong>Company: </strong><br/> ".stripslashes($jbco)."</td></tr>";
print "<tr><td><strong>Job Description: </strong><br/> ".stripslashes($jbdesc)."</td></tr>";
print "<tr><td><strong>Job Status: </strong><br/> ".stripslashes($jbstatus)."</td></tr>";
print "<td width=\"30\" bgcolor=\"990101\" rowspan=\"8\">\n";
    print "</tr>\n";
$row_count++;
  }


Thanks in advance for your help...

-Jacob
You can pass the ID in the URL and snag it on the other end using the $_GET statement or, as suggested, use sessions.

$id = $_GET['id'];

That 'snags' the ID from your url which is passed when your form is submitted like this:

<form action="parsethis.php?id=45XYZ" method="POST">

[quote]<form action="parsethis.php?id=45XYZ" method="POST">
[/quote]

should be
[code]<form action="parsethis.php?id=45XYZ" method="GET">[/code]

if you want to use POST use:
[code]$id = $_POST['id'];[/code]

or you can use the following code for both GET and POST
[code]$id = $_REQUEST['id'];[/code]
Id personally use POST, not GET. GET wacks the vars in the URL, which can be easily editable by users, to possibly access info that you dont want them to see. example...say if you had a user profiles script....

/view-users.php?getuser=Adam  would display info on the user Adam. but if the vars are easily viewable in the url, a visitor can easily change it to say /view-users.php?getuser=Administrator

yes i know GET isnt much better but at least the visitors carnt blatently see the vars.

BUT if you wanting to pass vars from pages to pages, use sessions as suggested above.
Unfortunatly I am not familiar with the session() method :(... I do have the form tag, it is elsewhere on the page of code... I guess it needs to be right next to the other stuff??? However, i think ill try the session() method if anyone has some basic info on how to use it in my case that would be great... Oh and thanks everyone else for your help so far...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.