hi, i have this code buts its not working exactly right. i wondered if anyone would have a second to look through it and let me know what im doing wrong...
code:
// check to see if the page is posted and data sent
if ($REQUEST_METHOD == "POST" && $HTTP_POST_VARS) {
//set variable to enable action printing
$a_arr_1=$HTTP_POST_VARS['comm'];
//add new entry
while(list($id,$newcname) = @each($newdetail)) {
if (!empty($newcname)){
$query = "INSERT INTO $table_name VALUES (NULL, '$newcname', '$newcmail', '$newcsite', '$newccomm', NULL)";
$res = mysql_query($query);
//print action statement
print "<div>Added <b>$a_arr_1
</b> to the database<br>\n</div>";
}
}
} // ends the post/vars check
// changes made - make query
$query = "SELECT * FROM $table_name ORDER BY commentid DESC";
$res = mysql_query($query);
// build the display array
while($row = @mysql_fetch_array($res)) {
$comment = array(name=>$row[commentname],mail=>$row[commentmail],site=>$row[commentsite],comm=>$row[commentcomment],dte=>$row[commentdte]);
$disp_array[$row[commentid]] = $comment;
}
?>
<table cellspacing='1' cellpadding='0' border='0' bgcolor='#ff0000'>
<form method='POST' action="<?= $PHP_SELF ?>">
<tr><td colspan="2">Submit new comment</td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcname ?>">
</td><td> </td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcmail ?>">
</td><td> </td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcsite ?>">
</td><td> </td></tr>
<tr><td><TEXTAREA NAME="newdetail[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $newccomm ?></TEXTAREA></td></tr>
<tr><td>Comments</td><td>Delete</td></tr>
<?
while(list($id,$comment) = @each($disp_array)) { ?>
<tr><td>Date added:<?= date("d.m.Y", strtotime($comment[dte])) ?></td><td align='center' rowspan='5'><input type="checkbox" name="delete[<?= $id ?>]" value="yes"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[name] ?>"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[mail] ?>"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[site] ?>"></td></tr>
<tr><td><TEXTAREA NAME="comm[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $comment[comm] ?></TEXTAREA></td></tr>
<? } ?>
<tr><td> </td><td align='center' height='35'><input type='image' src='images/gobutt.gif' name='sub' border='0'></td></tr></form></table></div>
the problems i am encountering are as follows:
* //add new entry
when you fill in the four textboxes they are added to the database but they dont go to the correct fields. it should be like.
textbox1 = name field
textbox2 = email field
textbox3 = site field
textbox4 = comment field
but it comes out like
textbox1 = name field
= blank
= blank
= blank
textbox2 = name field
= blank
= blank
= blank
etc...
* the date
this displays the date ok but it shows the same date for each row, im guessing its the last one added to the database.
* //print action statement
cant seem to make this work
there are some other bits of the script but i left them out because they are working ok, im pretty sure they dont affect the code that i printed here.
sorry about the long post!
thanks
give me all your lentils
code:
// check to see if the page is posted and data sent
if ($REQUEST_METHOD == "POST" && $HTTP_POST_VARS) {
//set variable to enable action printing
$a_arr_1=$HTTP_POST_VARS['comm'];
//add new entry
while(list($id,$newcname) = @each($newdetail)) {
if (!empty($newcname)){
$query = "INSERT INTO $table_name VALUES (NULL, '$newcname', '$newcmail', '$newcsite', '$newccomm', NULL)";
$res = mysql_query($query);
//print action statement
print "<div>Added <b>$a_arr_1
</b> to the database<br>\n</div>";
}
}
} // ends the post/vars check
// changes made - make query
$query = "SELECT * FROM $table_name ORDER BY commentid DESC";
$res = mysql_query($query);
// build the display array
while($row = @mysql_fetch_array($res)) {
$comment = array(name=>$row[commentname],mail=>$row[commentmail],site=>$row[commentsite],comm=>$row[commentcomment],dte=>$row[commentdte]);
$disp_array[$row[commentid]] = $comment;
}
?>
<table cellspacing='1' cellpadding='0' border='0' bgcolor='#ff0000'>
<form method='POST' action="<?= $PHP_SELF ?>">
<tr><td colspan="2">Submit new comment</td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcname ?>">
</td><td> </td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcmail ?>">
</td><td> </td></tr>
<tr><td>
<input name="newdetail[<?= $id ?>]" size="30" maxlength="70" value="<?= $newcsite ?>">
</td><td> </td></tr>
<tr><td><TEXTAREA NAME="newdetail[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $newccomm ?></TEXTAREA></td></tr>
<tr><td>Comments</td><td>Delete</td></tr>
<?
while(list($id,$comment) = @each($disp_array)) { ?>
<tr><td>Date added:<?= date("d.m.Y", strtotime($comment[dte])) ?></td><td align='center' rowspan='5'><input type="checkbox" name="delete[<?= $id ?>]" value="yes"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[name] ?>"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[mail] ?>"></td></tr>
<tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[site] ?>"></td></tr>
<tr><td><TEXTAREA NAME="comm[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $comment[comm] ?></TEXTAREA></td></tr>
<? } ?>
<tr><td> </td><td align='center' height='35'><input type='image' src='images/gobutt.gif' name='sub' border='0'></td></tr></form></table></div>
the problems i am encountering are as follows:
* //add new entry
when you fill in the four textboxes they are added to the database but they dont go to the correct fields. it should be like.
textbox1 = name field
textbox2 = email field
textbox3 = site field
textbox4 = comment field
but it comes out like
textbox1 = name field
= blank
= blank
= blank
textbox2 = name field
= blank
= blank
= blank
etc...
* the date
this displays the date ok but it shows the same date for each row, im guessing its the last one added to the database.
* //print action statement
cant seem to make this work
there are some other bits of the script but i left them out because they are working ok, im pretty sure they dont affect the code that i printed here.
sorry about the long post!
thanks
give me all your lentils