knightsofthesea Posted August 11, 2020 Share Posted August 11, 2020 I need some help please with mysql statement loop with a post form. I have displayed it as basic as I can. It populates fine. and it displays as a list with each persons details and a post button . But when I press the Post button of any on the list, the form gets populated with the first person on the list. I am a newbee thanks. <!DOCTYPE html> <html> <head> </head> <body> <?php // Create connection $conn = new mysqli($servername, $username, $password, $dbname); /// Check SQL connection if ($conn->connect_error) { echo"myerror"; // Get the the data from the database $sql = "SELECT * FROM details WHERE enrollid ='$enrollid' "; $result = $conn->query($sql); // Check database connection first if ($conn->query($sql) === FALSE) { echo"myerror"; } // If database connection is okay and sql connection else if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { ?> <div class="col-md-3 bid-section"> <!-- Favourites --> <form action="" method="post" > <!-- Favourites --> <input type="text" class ="firstname" name="" value="<?php echo $row['firstname'];?>"> <input type="text" class ="surname" name="" value="<?php echo $row['surname'];?>"> <input type="text" class ="country" name="" value="<?php echo $row['country'];?>"> <a class ="favourite-btn" > <div class="'.$favicon.'"></div> </a> </form> <div> <?php } }else { echo 'No Details'; } mysqli_free_result($result); mysqli_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/311318-recomm/ Share on other sites More sharing options...
requinix Posted August 11, 2020 Share Posted August 11, 2020 Are you using Javascript to submit the form? What's the code for that? Does it blindly look for a form on the page? Or is it smart and look for the form that contains the button that was clicked? You could probably skip all that Javascript stuff if you used a regular form submit button. Quote Link to comment https://forums.phpfreaks.com/topic/311318-recomm/#findComment-1580554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.