I have this while loops and an embedded if statement which places a hyperlink in the appropriate table cell. When I press edit the URL reflects what I want to see (which is the current word to be edited) but the text field the word is suppose to populate is only ever the first entry in the database table.
I have tried Using PHP variables inside HTML tags? which I think does not work because mine is an internal link, not another website.
I have also tried to store $row['yourword']
in another var, so when the while loop encounters that if statement which puts the edit in the right cell, it also would save the correct yourword, but it just results in an error.
Here is the while loop
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['uname'] . "</td>";
echo "<td>" . $row['clickrate'] . "</td>";
if($row['uname'] == $logedInUsername)
{
echo "<td>" . $row['yourword'] . "<a href='edityourword.php?edit=$row[yourword]'> edit</a></td>";
}
else
{
echo "<td>" . $row['yourword'] . "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
And here is the destination
<form action="edityourword.php" method="POST">
word: <input type="text" name="newName" value="<?php echo $row[yourword]; ?>"><br><br>
<input type="submit" value="Update">
</form>
The expected result should be the 2nd word showing up in the text field on the next page, instead of the first one each time, editing the word still works, but the text field is just populated with wrong one each time if it is not the user which is the first on the table.
Aucun commentaire:
Enregistrer un commentaire