I'm currently creating a dummy website under the scenario of an animal adoption agency, where I need to creating a HTML table that displays all animals available for adoption and allow the user to send an adoption request out to be approved by staff.
I have created this table using PHP while loops and have echoed a button on each row that will send the adoption request out to be approved by staff. my issue is that the buttons don't work for their specific row and when pressed sends off a request for all available animals and not for their specified row.
How do I make each button specific to their row?
Here is my code:
<tr>
<th>Name</th>
<th>Type</th>
<th>DateOfBirth</th>
<th>Description</th>
<th>Photo</th>
<th>Available</th>
<th>Owner</th>
<th>Adopt</th>
<tr>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);//put in place due to previous error: Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO.
$hostname="localhost"; //local server name default localhost
$username="root"; //mysql username default is root.
$password=""; //blank if no password is set for mysql.
$database="dc2410"; //database name which you created
mysql_connect($hostname, $username, $password);
mysql_select_db($database);
$sql=mysql_query("SELECT * FROM `animal` WHERE `available` = 'Yes'");
while($animal=mysql_fetch_assoc($sql)){
echo"<tr>";
$animal['animalID'];
echo "<td>".$animal['name']."</td>";
echo "<td>".$animal['type']."</td>";
echo "<td>".$animal['dateofbirth']."</td>";
echo "<td>".$animal['description']."</td>";
echo "<td>"?> <img src="<?php echo $animal['photo'] ?>" width="100px" height="100px"/> <?php "</td>";
echo "<td>".$animal['available']."</td>";
echo "<td>".$animal['owner']."</td>";
?>
<td><form><input type="submit" value="Adopt" name="adopt" onClick="
<?php
$req=mysql_query("INSERT INTO adoptionrequest(userID, animalID, approved) VALUES ('1','".$animal['animalID']."','Awaiting Approval')");
?>
" ></form></td>
<?php
echo"<tr>";
}
?>
</table>
onClick=" <?php $req=mysql_query("INSERT INTO adoptionrequest(userID, animalID, approved) VALUES ('1','".$animal['animalID']."','Awaiting Approval')"); ?> "that's not how it works, this code well be executed when generating the html.