How to pass information by clicking hyperlink?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Izzy123
    New Member
    • Apr 2010
    • 7

    How to pass information by clicking hyperlink?

    we are given a database, and we had to list the year of review, this is to be a hypertext link which when clicked will pass the reviewid(which is stored in the reviews table in the database) to the viewReview.php page

    the code I have for passing the reviewid to viewReview.php is this:
    Code:
    <td><a href="viewReview.php?reviewid=<?php echo $row1['reviewid'] ?>"><?php echo $row1["reviewYear"] ?></a></td>
    Then in the viewReview.php we had to display Employee informations according to the reviewid.

    But the problem is when I clicked on the link, it takes me to the viewReview.php page, it just displays all the Employee informations but it's not according to the reviewid. This is my code in the viewReview.php
    Code:
    <?php
    session_start(); 
    
    $conn = mysql_connect("localhost", "TWA2", "test");
    mysql_select_db("performancereview", $conn)
    or die ('Database not found ' . mysql_error() );
    $sql = "SELECT employee.empid, jobs.jobtitle, employee.extension, departments.departmentname, reviews.supervisorid, reviews.reviewYear FROM employee, jobs, reviews, departments WHERE jobs.jobid=employee.jobid AND employee.empid=reviews.empid ";
    $rs = mysql_query($sql, $conn)
    or die ('Problem with query' . mysql_error());
    
    ?>
    
    <table border="1">
    <tr>
    <th>Employee id</th>
    <th>Job Title</th>
    <th>Phone Extension</th>
    //rest of the <th>
    </tr>
    <?php
    while ($row = mysql_fetch_array($rs)) { ?>
    <tr>
    <td><?php echo $row["empid"]?></td>
    <td><?php echo $row["jobtitle"]?></td>
    <td><?php echo $row["extension"]?></td>
    //rest of the <td>
    </tr>
    <?php }
    mysql_close($conn); ?> 
    </table>
    I'm thinking I have to add something in my viewReview.php, something like reviewid=...., but I'm not sure what to add...
    can anyone help please.
  • Baul
    New Member
    • May 2010
    • 3

    #2
    Hi,

    you have to get the reviewid from either the $_GET- or the $_REQUEST-Array:

    Code:
    $reviewid = intval($_REQUEST['reviewid'];
    $_REQUEST hold the values from $_GET and $_POST

    Now you have to use this value in your SQL-Query by adding something like
    Code:
    AND reviews.id = $reviewid
    Sorry, but I don't know anything about your database structure so I can't tell you if the field name rewiews.id is correct.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      $_REQUEST holds the contents of $_GET, $_POST and $_COOKIE, in fact. With this comes a few (small) issues:
      1. If in your $_GET array you have the index $username, which is created via some add-user admin form, and you have, in your $_COOKIE array, an index also named 'user', depending on the request_order directive of your php.ini configuration file, one of the values will be overwritten, leading to often unintentional behaviour;
      2. ambiguity - when someone maintains your code, if they see $_GET, you can correctly assume you're taking data from a URL, and as such can determine things about your code - is the data sensitive ($_GET data shouldn't be);
      3. and finally there is a slight speed difference.

      Comment

      Working...