Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery forms.js with multiple forms per page
    primarykey
    data
    text
    <p>I would like to submit information to a mySql database using php and ajax.</p> <p>The page that the info is being sent from (form.php) has multiple forms that are generated from a "while()" loop.</p> <p>On success, I would a response to update a div above the particular form from which the data was submitted.</p> <p>I am currently using jQuery and the <a href="http://malsup.com/jquery/form/#getting-started" rel="nofollow noreferrer">jquery form plugin</a>.</p> <p>I have been successful in getting the data to the database, however I am having trouble with the response being sent back to the proper div. I have been successful in getting a response back to a div that is outside of the while() loop. I have not, however, been successful in getting a response back to a div within the loop. I have placed in the code below a div called: "> Where I would like the note to be placed.</p> <p>I know that this has everything to do with my javascript function:</p> <pre><code>&lt;script type="text/javascript"&gt; jQuery(document).ready(function() { jQuery('form').ajaxForm({ target: '#noteReturn', success: function() { $('#noteReturn').fadeIn('slow'); } }); }); &lt;/script&gt; </code></pre> <p>The #noteReturn function does not specify which businesses div it should be placed in.</p> <p>I hope that this makes sense.</p> <p>Thank you for your help.</p> <p>The code is below:</p> <pre><code>&lt;!-- the form.php page --&gt; &lt;script type="text/javascript" src="js/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/forms.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function() { jQuery('form').ajaxForm({ target: '#noteReturn', success: function() { $('#noteReturn').fadeIn('slow'); } }); }); &lt;/script&gt; &lt;?php $query = mysql_query("SELECT * FROM businesses"); while( $row = mysql_fetch_assoc( $query ) ): $b_id = $row['bid']; ?&gt; &lt;div class='notes'&gt; &lt;?php // query the db for notes associated with business... return notes texts and notes dates $notesQuery = mysql_query("SELECT business_id, notes, messageDate FROM notes WHERE notes.business_id = $b_id ORDER BY messageDate"); while( $NoteRow = mysql_fetch_assoc( $notesQuery ) ) { extract($NoteRow); echo "$notes&lt;br/&gt;&lt;span class='noteDate'&gt;$messageDate&lt;/span&gt;&lt;br /&gt;"; } // end while$notesQuery ?&gt; &lt;!-- this is where i would like jQuery to return the new note --&gt; &lt;div id="noteReturn&lt;?php echo $b_id; ?&gt;"&gt;&lt;/div&gt; &lt;!-- begin note form --&gt; &lt;form name="noteForm" action="notesProcess.php" method="post"&gt; &lt;input type="text" name="note" /&gt; &lt;input type="hidden" value="&lt;?php echo $b_id ?&gt;" name="bid" /&gt; &lt;input type="submit" class="button" value="Send" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;!-- end div.notes --&gt; &lt;?php endwhile; ?&gt; &lt;!-- ///////////////////////////////////////////////////// The page that the form submits to is this (notesProcess.php): ///////////////////////////////////////////////////// --&gt; &lt;?php $note = $_POST['note']; $id = $_POST['bid']; $sql = "INSERT INTO notes (business_id, notes) VALUES ('$id', '$note')"; $result = mysql_query( $sql ); if( $result ) { echo " $note"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload