I'm trying to select commenter from a table called comments then select username from a table called users using a where clauses from the details from the first table. After that update comments set username to the usernames obtained from table 2.
This is my code:
<?php
include("connection.php") ;
$sql=mysqli_query($link, "SELECT * FROM comment ORDER BY id ASC" ) ;
while($row=mysqli_fetch_assoc($sql)){
$commenter=$row['commenter'] ;
$sqli=mysqli_query($link, "SELECT * FROM users WHERE fullname='$commenter' ORDER BY id ASC" ) ;
while($rows=mysqli_fetch_assoc($sqli)){
$username=$rows['username'] ;
$sql_u=mysqli_query($link, "UPDATE comment SET username='$username' WHERE commenter='$commenter' " ) ;
}
}
?>
The code above only updates one row