Hi, This might be more appropriate in the PHP section, I'm not sure - still a newb.

I have read this problem in other threads, but can't seem to make the solutions work for me. I have a table that shows the results of a query for either pat_id or surname. I want the user to be able to click on a hyperlink of pat_id (there might be many rows) and for that pat_id to be sent to another php page that shows the related information for that patient ONLY.

Here is my code so far, at the moment the hyperlink goes to www.yahoo.com. I don't want to send the pat_id variable via the URL (ie a $_GET method) as I need it to be private.

<?php
while($row = mysql_fetch_array($result))
  {
  echo "<tr>"; 
  echo "<td>" . "<a href=\"http://www.yahoo.com\">"  . $row['pat_id'] . "</a>" . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['middlename'] . "</td>";
  echo "<td>" . $row['surname'] . "</td>";
  echo "<td>" . $row['dob'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
  echo "<td>" . $row['sex'] . "</td>";
  echo "<td>" . $row['phone'] . "</td>";
  echo "<td>" . $row['phone_alt'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['hospital'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
?>

Moved to PHP.

so I think I have made some progress. I seem to be able to get the hyperlink to post, but only to send the first value returned by the query.

At the moment I have 4 results on the page, pat_id's 123456, 123457, 666666, 888888. If you click on the hyperlink for 888888, it still posts 123456 to the next page.

while($row = mysql_fetch_array($result))
  {
  
  echo "<tr>"; 
  echo "<td>" ;
  echo "<form id=\"myForm\" method=\"post\" action=\"background_current.php\">";
  echo "<INPUT TYPE=hidden NAME=select_pat_id VALUE=" . $row['pat_id'] . "></input>" . "<a href=\"#\" onclick=\"document.forms[0].submit();\">" . $row['pat_id'] . "</a>" . "</td>"; 
		echo "</form>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['middlename'] . "</td>";
  echo "<td>" . $row['surname'] . "</td>";
  echo "<td>" . $row['dob'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
  echo "<td>" . $row['sex'] . "</td>";
  echo "<td>" . $row['phone'] . "</td>";
  echo "<td>" . $row['phone_alt'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['hospital'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close();

?>

I think I know what is the problem, your syntax is incorrect:

echo "<form id=\"myForm\" method=\"post\" action=\"background_current.php\">";
  echo "<INPUT TYPE=hidden NAME=select_pat_id VALUE=" . $row['pat_id'] . "></input>" . "<a href=\"#\" onclick=\"document.forms[0].submit();\">" . $row['pat_id'] . "</a>" . "</td>"; 
		echo "</form>";

Change it so its all the html tags have " interpreted as '.
Do you know that syntax?
Example:

// Note: Substitued the " for the ' so php can function correctly
echo "<a href='www.domain.com'>domain</a>"

Understand? Let me know how you go.

OK, so I've done that, thanks, will save a lot of wasted time with the backslashes, but it hasn't changed the variable that's being posted.

If this page has multiple outputs from the query, it only posts the first one. If this page only has one output from the query it will pass the correct value (but only cos its the first one). Make sense?

Is $row an array? Should I be referencing which value I want? How would I do that?

Here is the source of this page as seen by the browser:

<table border='1'>
<tr>
<th>pat_id</th>
<th>firstname</th>
<th>middlename</th>
<th>surname</th>
<th>dob</th>
<th>age</th>
<th>sex</th>

<th>phone</th>
<th>phone_alt</th>
<th>address</th>
<th>hospital</th>
</tr><tr><td><form id='myForm' method='post' action='background_current.php'><INPUT TYPE=hidden NAME=select_pat_id VALUE=123456></input><a href='#' onclick='document.forms[0].submit();'>123456</a></td></form><td>John</td><td>Ranyard</td><td>Smith</td><td>1983-11-29</td><td>0</td><td>male</td><td>439779288</td><td>439778954</td><td>gaushala</td><td>tilganga</td></tr><tr><td><form id='myForm' method='post' action='background_current.php'><INPUT TYPE=hidden NAME=select_pat_id VALUE=123457></input><a href='#' onclick='document.forms[0].submit();'>123457</a></td></form><td>John</td><td>Ranyard</td><td>Smith</td><td>1983-11-29</td><td>0</td><td>male</td><td>0439779288</td><td>0439778954</td><td>gaushala</td><td>tilganga</td></tr><tr><td><form id='myForm' method='post' action='background_current.php'><INPUT TYPE=hidden NAME=select_pat_id VALUE=666666></input><a href='#' onclick='document.forms[0].submit();'>666666</a></td></form><td>John</td><td>Ranyard</td><td>Smith</td><td>1983-11-29</td><td>0</td><td>male</td><td>0439779288</td><td>0439778954</td><td>gaushala</td><td>tilganga</td></tr><tr><td><form id='myForm' method='post' action='background_current.php'><INPUT TYPE=hidden NAME=select_pat_id VALUE=888888></input><a href='#' onclick='document.forms[0].submit();'>888888</a></td></form><td>John</td><td>Ranyard</td><td>Smith</td><td>1983-11-29</td><td>0</td><td>male</td><td>0439779288</td><td>0439778954</td><td>gaushala</td><td>tilganga</td></tr></table>

Sorry I cant read your code maybe put it in code brackets.
If you are using mulltiple values you wish to store then an array should be used.

I'm not having a problem storing the values or displaying them, I'm just having a problem posting ONE of them to the next page. Make sense?

I think I found the Problem:
dash your codes a mess still.
Make sure all tags parameters type, name, value, onclick, etc all start and end with either a " or if its in echos a '.
Values dont seem to be inside quotes and this maybe why you are unable to pass on values.
Let me know how that goes and what are the results.

Side Note: Also to pass variables onto the next page you will have to use sessions or pass them through a link.

dash your codes a mess still.
Make sure all tags parameters type, name, value, onclick, etc all start and end with either a " or if its in echos a '.
Values dont seem to be inside quotes and this maybe why you are unable to pass on values.

It may be a mess, but it is running. I am gonna need something more useful than " needs to change to ', because not only have I done that, the values are obviously showing up, that's why I included the HTML that the browser sees.

Side Note: Also to pass variables onto the next page you will have to use sessions or pass them through a link.

That's what my original question was! How to get the values to pass through the link. I'm sorry, I do appreciate the time you have taken out to help me out, but I can't help but feel you're not focusing on the problem.

The problem BTW, was just that I was overwriting the variable that was being posted:

"<a href='#' onclick='document.forms[0].submit();'>"

should have been :

"<a href='#' onclick='document.forms[" . $i . "].submit();'>"

with the variable $i incrementing as each row in the table is echoed.

If you could suggest a cleaner way of doing that I'd appreciate it.

Your not listening or doing any of the posts reread them.
Till then im not giving you anymore of my time.

I did everything you said. My last post shows the solution.

you can store the field values in a hidden fields and use them on next page. and that will be hidden and will not show to others. This will work for you. and when we click on the hyperlink then the hidden field values will also be posted and can be use on another page.

Thanks
Rahul Anand

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.