Jump to content

[SOLVED] Form handling in a loop for mysql


emma57573

Recommended Posts

Im not quite sure how to handle the output of this loop

 

 

 

$freetplquery="select * from mytable_sold where seller=".$userid." or buyer=".$userid."";
$sql=mysql_query($freetplquery);
$rst=mysql_fetch_array($sql);
?>

MY LEAVE FEEDBACK FORMS

              <table>
                <tr> 
                  <td> 
                    <? if ($rst) { ?>

                     <FORM name="leavefeed" method="POST" action="updatefeedback.php"  onsubmit="return Validate(this);">

<table>
                     
                      <?  $cnt=0;
                      while($rst){
				  
$aid=mysql_fetch_array(mysql_query("select * FROM MYTABLE_products WHERE user=".$rst["pid"]));

              ?>


<table>
         <tr> 
	<td><? echo $aid["product_name"];?></td>

 </tr>
         <tr>     
                
                 <td><input name="feedbox<? echo $rst["pid"]; ?>" type="radio" value="" /><h2>Positive</h2></td>
                 <td><input name="feedbox<? echo $rst["pid"]; ?>" type="radio" value="" /><h2>Neutral</h2></td>
	 <td><input name="feedbox<? echo $rst["pid"]; ?>" type="radio" value="" /><h2>Negative</h2></td>
                 <td><input name="feedbox<? echo $rst["pid"]; ?>" type="radio" value="" /><h2>Not Now</h2><br /></td>

       </tr>
<tr>
					   
	<td><b>Comments:</b><br />

                       <textarea name="comments<? echo $rst["pid"]; ?>"></textarea>

               </td>   

        </tr>

</table><br />
              
                      <?
				  $rst=mysql_fetch_array($sql);
        			  $cnt++;            
				}// end while
				?>
                 

			 <input name="submit" type="submit" value="Submit your Feedback" />



			  </td>
                                         </tr>  
                                               </table>
				</form>


 

Ive tried to simplify this as much as possible so the code is watered down.

When it gets to this page 'updatefeedback.php'

The data is added to a mysql table. Thats where im stuck.

How do I enter while loop details into a database?

Do I need to create a simular loop in 'updatefeedback.php' that writes to mysql after every loop? and if so how do i pick up the form data as a loop. Or is there a simply way of doing this and im making life hard on myself (as usual!)

 

 

 

The form works fine basically all I need to know is how to create an array from the form data onto the next submit page. So I can then put it into a loop and submit what I need to into mysql.

 

Does that make sence? I just want to know if its possible to get the data into an array and how I would go about it? Im at a bit of a loose end with this.

Ok Ive written a bit of code that I thought would work!

I dicided to use the same loop as the previous page in the same order and then do a mysql insert in the loop

		                     
				if ($rst)
			    {

				  $cnt=0;
                      while($rst)
				  {
				  

				  
				  $pid=$rst["pid"]; 

					$feed_score=$_POST["feedbox$pid"];
					$feed_comm=$_POST["comments$pid"];

              $insert= "INSERT INTO freetplclassified_feedback (user_id,score,comment,from_id,id,getdae,pro_id)VALUES('$userid','$feed_score','$feed_comm','$userid','','','$pid')";
mysql_query($insert);

if(mysql_affected_rows()>0){ ?>
Worked!!
<? }else{ ?>
Went wrong
<? }


				  $rst=mysql_fetch_array($sql);
        			  $cnt++;            
				}// end while

 

The loop is working but the insert to mysql isnt. Im not sure if im calling the $_POST right as it also has a variable in the name. I think this could be where im going wrong????

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.