Reputation: 1
I have problems to get the right GET-method for my results.
I have a script which shows me some results of my database. It works with Ajax:
$suchbegriff = $_POST["suchbegriff"];
if ($_POST["suchbegriff"]){
$sql = "SELECT * FROM user WHERE vorname OR nachname LIKE '%$suchbegriff%'";
$result = $conn->query($sql);
echo "<br>Sie suchten nach: ".$suchbegriff."<br>";
while($row = $result->fetch_assoc())
{ echo "<form action=\"profil.php\" method=\"get\">".$row['nachname'];
echo $row['vorname']."</a> <input type=\"submit\">";
echo "<br/>";}
}
Now I want to get the ID of the search-results to bring it with GET/POST to an other page called profil.php (unique user-profile):
<div class="col-xl-12">
<div class="col-xl-2">
<p>Vorname</p>
</div>
<div class="col-xl-5">
<p><?php
$sql = "SELECT vorname FROM user WHERE ID = $_GET[nachname]";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo $row['vorname'];
?></p>
</div>
</div>
Is there a way to couple nachname and vorname (name, surname) in the SQL-Statement? And how can I get the unique profile-URL from the search-results?
Thank you.
Upvotes: 0
Views: 116
Reputation: 782765
Change your first script to print a list of anchors, and put the ID into the href
URL.
while($row = $result->fetch_assoc())
{
echo "<a href=\"profil.php?nachname=".$row['id'].\">".$row['nachname']. " ".$row['vorname']."</a>";
echo "<br/>";
}
Upvotes: 1