Jump to content

recomm


knightsofthesea

Recommended Posts

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);

?>
 
 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.