Reputation: 6679
I have a weird problem with my code.
I'll explain.
I have 2 pages. I want to go from one page to another page. I have to show information that belongs to the link, deepending on which link I click. Now I use:
<a href=profile.php?comment_username={$comments['username']}>{$comments['username']}</a>
So I am using this in 3 different situations. 2 are working but the other one isn't:
Page 1:
$sql_result = $mysqli2->query("SELECT * FROM questions");
while ($thread = mysqli_fetch_assoc($sql_result)) {
echo <<<EOT
<table>
<th><a href=thread.php?thread_id={$thread['thread_id']}> {$thread['title']} </a></th>
</table>
EOT;
$_SESSION['idcheck']=$thread['thread_id'];
}
Page 2:
$thread_id =$mysqli2->real_escape_string($_SESSION['idcheck']);
$sql_result = $mysqli2->query("SELECT * FROM questions WHERE thread_id = '".$thread_id."'");
So now I can show the result on the page.
page 1:
while ($plant = $resultaat->fetch_assoc()){
echo <<<EOT
<form method="get" action="sql.php">
<a href="plant.php?plantcode={$plant['plantcode']}"> {$plant['plantnaam']} </a>
//some more stuff
</form>
EOT;
}
page 2:
$plantcode = $_GET['plantcode'];
$resultaat = $mysqli->query("select plantcode, plantnaam, kleur, soort, prijs, hoogte, bloeitijd_start, bloeitijd_einde from plant where plantcode={$plantcode}");
Again after all this I can show the information that belongs to the link they click.
Now my problem.
I don't think I can use either of them. In the 1st example I am using SESSIONS
, which I can't do in my 3rd one because it's a question/comment page and you can click on the usernames but usernames of the comments are in a different sql table. I actually tried SESSIONS
but when I click on comments usernames, it will direct to the username that belongs to the question.
At my 2nd page I am using a form so I can use GET
. I could use that but I actually dont want to use a form. So these are my problems.
Sorry for making it so vague.
What I actually want to know is, I know how to redirect with 1 variable and then show the information that belongs to it, but my question/comments page has 2 different variable but should still go to the same page when clicked and show the information that belongs to the username. So I use: SELECT * FROM account_information WHERE username = '".$profileusername."'
> Which I cant with 2 variables
This is my situation:
Page 1:
<a href=profile.php?thread_username={$thread['username']}> {$thread['username']}</a>
<a href=profile.php?comment_username={$comments['username']}>{$comments['username']}</a>
Page 2:
Depending which link they click, the value should come here:
$profileusername =$mysqli2->real_escape_string();
$sql_result = $mysqli->query("SELECT * FROM account_information WHERE username = '".$profileusername."'");
Upvotes: 0
Views: 324
Reputation: 6148
Link would either be:
<a href="http://mysite.com/?thread_username=THREAD_USERNAME" >Thread Username </a>
<a href="http://mysite.com/?ccomment_username=COMMENT_USERNAME">Comment Username</a>
To check which it is:
if(!empty($_GET['thread_username'])){
//If thread username link was clicked
$profileusername = $_GET['thread_username'];
}
else if(!empty($_GET['comment_username'])){
//If comment username was clicked
$profileusername = $_GET['comment_username'];
}
else{
//No username has been entered
}
//Continue with rest of your code:
$profileusername =$mysqli2->real_escape_string();
$sql_result = $mysqli->query("SELECT * FROM account_information WHERE username = '".$profileusername."'");
Upvotes: 1