mysql links

I’m having some trouble trying to figure out how to make a link out of a table with mysql data.

What I have is a table from a mysql database from a job application. The table only contains basic information of the applicant’s id, name and contact info. I’d like to have the ID as a link that would lead the user to a page that has the detailed information from the job app. So far I have both pages, I just need to figure out how to do that link with the ID.

Here’s the table page where I would like to have the ID link.
[php]

<?php include("password_protect.php"); $con=mysqli_connect("localhost","user","pass","user"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM jobapp ORDER BY ID"); echo ""; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
ID Name Address City State Zipcode Phone
" . $row['id'] . "" . $row['first'] . " " . $row['middle'] . " " . $row['last'] . "" . $row['address1'] . ", " . $row['address2'] . "" . $row['city'] . "" . $row['state'] . "" . $row['zip'] . "" . $row['phone'] . "
"; mysqli_close($con); ?>

[/php]

Here’s the php that it should be linked to. Here it’s the number 4 but I’d like it to be the variable that’s passed.

[php]

<?php mysql_connect("localhost","user","pass") or die(mysql_error()); mysql_select_db("user") or die(mysql_error()); $result = mysql_query("SELECT * FROM jobapp WHERE id='4'") or die(mysql_error()); $row = mysql_fetch_array( $result ); ?>

[/php]

So, in essence, I’m not sure how to pass a variable from one page to the next. Do you do it in a hidden form or can you pass it in some other way? Thanks!

Somethine like this should work for you

[php]echo “

<a href=‘www.yourdomain.com/yourpage.php?id=’ . $row[‘id’] . '>” . $row [‘id’] . “”; [/php]

And on the linked page.

[php] $result = mysql_query(“SELECT * FROM jobapp WHERE id=’” . $_GET[‘id’] . “’”); [/php]

Thanks so much for helping. Its very nice when people take some time out to help others.

Unfortunately, I had an “o oh” moment after playing with it for a bit. The table page is password protected, so I believe that page is ok, but for the second page, all that’s needed is to replace id= with the numbers leading to it and they’d be able to see all the user info. So, I found found a unique number script and thought I could use it as a hidden value input. it doesn’t work though.

[php]

<?php $userid = uniqid(rand(),true); echo $userid; ?>

[/php]

This is what I’ve been using. The echo has a nice long random number, but when i try to insert that into a text box, it places $userid = uniqid(rand(),true); into the database. Can someone see where I’m going wrong?

I’m not sure what you mean by

The echo has a nice long random number, but when i try to insert that into a [b]text box[/b], it places $userid = uniqid(rand(),true); into the [b]database[/b]. Can someone see where I'm going wrong?

I don’t see anywhere in the code, where you are trying to put the value into a textbox or a database. you are just putting it into a hidden field.

sorry, my mind’s a fog at this point from working on it.

What I’m trying to get it to do is to generate this nice long unique code and through a hidden input, put it in the database.

So far I’ve gotten it to generate a nice long id with this:

[php]

<?php $userid = uniqid(rand(),true); echo $userid; ?>

[/php]

maybe not perfectly random, but close.

But where I fall apart is trying to insert that number into my hidden input.

[php]

[/php]

The value it places into the database is

$userid = uniqid(rand(),true);

rather than the number it thought up earlier. I’m pretty sure it has to do with how I’m writing the html for the hidden input box, but I’m not sure what it would be. I’ve tried a bunch of different things and nothing’s helped. thanks for looking at this.

I’m not sure why it’s not working for you, I copied your code and pasted in a .php file and it works perfectly.

You can check it out here.

http://phphelp.com/forum/membershelp/itgrannytest.php

If you view the source in your browser you will see the correct value in the hidden field.

Thank you! Thank you! I found where I messed up. After those lines I had some comments and then i had left an earlier failed attempt line there, in essence changing the variable.

Thanks so much for your help!

;D

Sponsor our Newsletter | Privacy Policy | Terms of Service