This is my fetch.php file which works currently but I can't seem to connect my php hyperlink to the gene.php file.
I'm thinking about how I can separate the html from the php to follow other suggestions but struggling on how to do this.
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td><a href="gene.php?id=' . $row['mRNA'] . '">'.$row["mRNA"].'</a></td>
<td><a href="gene.php?id=' . $row['mRNA'] . '">'.$row["Gene"].'</a></td>
<td>'.$row["Subtype"].'</td>
</tr>
';
}
echo $output;
}
?>
If possible, I'm hoping I could pass the new gene.php?id variable back as a query on my gene.php page.
<?php
$connect = mysqli_connect("localhost", "root", "", "database");
$id[0] = $_REQUEST['id'];
$query = "SELECT * FROM genenames WHERE mRNA=".$id."";
$id[0] = $_REQUEST['id'];should probably just be$id = $_REQUEST['id'];You need to read up on SQL injection. You can never trust user input.mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe SQL injection bug. NEVER put$_POST,$_GETor any user data directly into a query, it can be very harmful if someone seeks to exploit your mistake.mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…")The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code.