Techiio-author
Started by Bell GrantNov 7, 2021

Open
How to insert more than 1 row into foreign key table in php mysql?

3 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWES SHARE
$notice = "SELECT id FROM notification
    WHERE noti_user ='Pro'";
$noticeqry = mysqli_query($con, $notice); 
$sql = "INSERT INTO `user_notification` (`notif_id`, `user_id`) 
  values while($noticerow = mysqli_fetch_array($noticeqry)){("$noticerow['id']", "$univuid"}";
  $query= mysqli_query($con,$sql);

Not working and getting error Parse error: syntax error, the unexpected variable "$noticerow"

1 Replies

Techiio-commentatorBruno Fernandez replied 4 months ago0 likes0 dislikes

Maybe you can try insert through for loop, like this:

$notice = "SELECT id FROM notification WHERE noti_user ='Pro'";
$noticeqry = mysqli_query($con, $notice); 
$row = $noticeqry->fetch_assoc();
$count_id = mysqli_num_rows($noticeqry);
for($i=0; $i < $count_id; $i++){
    $noticerow = $row['id'][$i];
    $sql = "INSERT INTO `user_notification` (`notif_id`, `user_id`) values ('$noticerow', '$univuid')";
    $query= mysqli_query($con,$sql);
}
if($query) {
    echo "New record created successfully";
} else { 
    echo "Error: " . 
You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance