I have been trying to figure this out now for 30 hours, could really use the help.

I have a php script that pulls a list of campaigns from the mysql db and displays them in individual forms with unique data within common field names.

Upon the Submit function it sends that information over to another php file and executes the php.

I am stuck dealing with the dreaded Last Row, where the only data to post is the last row that was loaded in the loop. I have tried creating unique names and such, but feel that the actual problem lies in the ajax code. Anyways here is my ode.

I have tried these 2 versions of javascript/ajax

<script type="text/javascript" >
$(function() {
$(".submit").click(function() {
var email = $("#email").val();
var campaign = $("#campaign").val();
var dataString = 'email='+ email + '&campaign=' + campaign;

if(email=='' || campaign=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "sendmail.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
</script>


$( '#form' ).submit( function() { $.post( 'sendmail.php' , $( this ).serialize() ,           function( response ) { do_something_with_server_response(); } ); } );





while ($row = mysql_fetch_array( $campaign_query )) {
?>
<?php
$campaign_id = $row['campaign_uid'];
$email_address = $row['email'];
?>

<form name="form" method="post">

<tbody>
<tr>

<td><h4><?php echo $row['advertisement_name']; ?></font></h4></td>
<td><h4><?php echo $row['short_description']; ?></font></h4></td>
<td><h4><?php echo $row['category']; ?></div></font></h4></td>
<td><h4><div onmouseover="setFirstChildImgDisplay(this,'block')"        onmouseout="setFirstChildImgDisplay(this,'none')"><button id="fat-btn" class="btn btn-    primary">Preview +$
 <td><h4>
             <input type="hidden" name="email" id="email" value="<?php echo    $email_address; ?>">
            <input type="hidden" name="campaign" id="campaign" value="<?php echo    $campaign_id; ?>">
               <button type="submit" class="submit btn btn-primary" value="Submit">Send   Ad</button></font></h4></td>

</form>
<?php
 }
?>
share|improve this question
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.