Forum Moderators: coopster
I have a ratings sytem working I now need to allow visitors to comment on each rating
for example I have 6 ratings on the page and a sliding panel for each to post comment
now this works fine until you submit a comment, the problem is the comment is inserted 6 times
the reason for this is KT_Insert1 my submit button
so what seems to be happening is all the forms are inserting, the submit button has to be different for each one KT_Insert<?php echo $row_rs3['rating_id']?>
Now here comes the main problem Registertrigger won't allow this variable but insert will?
maybe this can't be done with dreamweaver developer toolbox, if this is the case can someone please provide me with a simular altenative?
// Make an insert transaction instance
$ins_restaurant_comments = new tNG_insert($conn_connDW);
$tNGs->addTransaction($ins_restaurant_comments);
// Register triggers
$ins_restaurant_comments->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert{rs3.rating_id}");
$ins_restaurant_comments->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
// Add columns
$ins_restaurant_comments->setTable("restaurant_comments");
$ins_restaurant_comments->addColumn("name", "STRING_TYPE", "POST", "name");
$ins_restaurant_comments->addColumn("rating_id", "NUMERIC_TYPE", "VALUE", "{rs3.rating_id}");
$ins_restaurant_comments->addColumn("message", "STRING_TYPE", "POST", "message");
$ins_restaurant_comments->addColumn("created", "DATE_TYPE", "POST", "created", "{NOW_DT}");
$ins_restaurant_comments->addColumn("onhold", "NUMERIC_TYPE", "POST", "onhold", "1");
$ins_restaurant_comments->setPrimaryKey("comment_id", "NUMERIC_TYPE");
I have not worked with DW toolbox but let me try to help you with my experience.
Are you using six forms, one form for each comments page for each listing, or you are using a single comments form?
if you are using six forms, which is discouraged by me at least, then the work around could be to give each form a unique name, if you are using AJAX on the receiving end, otherwise make a HIDDEN form field for each form and assign it the PRIMARY KEY OF EACH LISTING.
On the receiving page, use the unique hidden field value or form name with ajax code to recognize which form has been posted. And run the INSERT query only for that form.
The bottom line is that your INSERT query code must get a UNIQUE value from your comments form, related to the listing. So that it can determine which listing comment is going to be inserted and can run the query only once.
so there be 6 comments with slidding panels for the forms
or another outlet may have 2 and so on
I have tried to make my form name dynamic using
<?php echo $row_rs3['rating_id']?> after the name so each entry would be different, but it always inserts multiple entires when I only need one at the time, please someone help me with this, this is very stressfull issue for me and can't continue until i get this to work correctly.
<form method="post" id="form1<?php echo $row_rs3['rating_id']?>" action="<?php echo KT_escapeAttribute(KT_getFullUri());?>">
<table width="98%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td><label for="name">Name:</label></td>
<td><input type="text" name="name" id="name" value="<?php echo KT_escapeAttribute($row_rsrestaurant_comments['name']);?>" size="32" />
<?php echo $tNGs->displayFieldHint("name");?> <?php echo $tNGs->displayFieldError("restaurant_comments", "name");?> </td>
</tr>
<tr>
<td valign="top"><label for="message">Comment:</label></td>
<td><textarea name="message" id="message" cols="55" rows="5"><?php echo KT_escapeAttribute($row_rsrestaurant_comments['message']);?></textarea>
<?php echo $tNGs->displayFieldHint("message");?> <?php echo $tNGs->displayFieldError("restaurant_comments", "message");?> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="KT_Insert10" id="KT_Insert10" value="Insert record" /><?php echo $row_rs3['rating_id']?></td>
</tr>
</table>
<input type="hidden" name="created" id="created" value="<?php echo KT_formatDate($row_rsrestaurant_comments['created']);?>" />
<input type="hidden" name="onhold" id="onhold" value="<?php echo KT_escapeAttribute($row_rsrestaurant_comments['onhold']);?>" />
</form>
<?php
/*MOVED out of loop*/
mysql_select_db($database_connDW, $connDW);
$query_rs5 = "SELECT * FROM restaurant_comments WHERE rating_id = '$commentid'";
$rs5 = mysql_query($query_rs5, $connDW) or die(mysql_error());
$row_rs5 = mysql_fetch_assoc($rs5);
$totalRows_rs5 = mysql_num_rows($rs5);
if ($totalRows_rs5!= 0) { do
{
$cmessage = $row_rs5['message'];
$cname = $row_rs5['name'];
$ccreated = $row_rs5['created'];
?>
<table width="100%" border="1" cellpadding="6" cellspacing="0" bordercolor="#FFCC00" bgcolor="#FFFFEA"><tr><td bgcolor="#FFFFFF"><p><strong><?php echo $cname?></strong> comments - <?php echo $ccreated?>
<br>
<?php echo $cmessage?></p></td></tr></table>
<?php
} while ($row_rs5 = mysql_fetch_assoc($rs5));
}
mysql_free_result($rs5);?></td></tr></table>
</div></td></tr></table><br>
<?php } while ($row_rs3 = mysql_fetch_assoc($rs3));
mysql_free_result($rs4);
?>