Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help debugging a guestbook type of thing

Status
Not open for further replies.

lentildal

Programmer
Sep 24, 2001
25
GB
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 &quot;<div>Added <b>$a_arr_1



</b> to the database<br>\n</div>&quot;;



}

}



} // ends the post/vars check



// changes made - make query



$query = &quot;SELECT * FROM $table_name ORDER BY commentid DESC&quot;;

$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=&quot;<?= $PHP_SELF ?>&quot;>



<tr><td colspan=&quot;2&quot;>Submit new comment</td></tr>

<tr><td>

<input name=&quot;newdetail[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $newcname ?>&quot;>

</td><td> </td></tr>

<tr><td>

<input name=&quot;newdetail[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $newcmail ?>&quot;>

</td><td> </td></tr>

<tr><td>

<input name=&quot;newdetail[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $newcsite ?>&quot;>

</td><td> </td></tr>

<tr><td><TEXTAREA NAME=&quot;newdetail[<?= $id ?>]&quot; ROWS=4 COLS=26 WRAP=&quot;virtual&quot;><?= $newccomm ?></TEXTAREA></td></tr>

<tr><td>Comments</td><td>Delete</td></tr>

<?

while(list($id,$comment) = @each($disp_array)) { ?>

<tr><td>Date added:<?= date(&quot;d.m.Y&quot;, strtotime($comment[dte])) ?></td><td align='center' rowspan='5'><input type=&quot;checkbox&quot; name=&quot;delete[<?= $id ?>]&quot; value=&quot;yes&quot;></td></tr>

<tr><td><input name=&quot;comm[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $comment[name] ?>&quot;></td></tr>

<tr><td><input name=&quot;comm[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $comment[mail] ?>&quot;></td></tr>

<tr><td><input name=&quot;comm[<?= $id ?>]&quot; size=&quot;30&quot; maxlength=&quot;70&quot; value=&quot;<?= $comment[site] ?>&quot;></td></tr>

<tr><td><TEXTAREA NAME=&quot;comm[<?= $id ?>]&quot; ROWS=4 COLS=26 WRAP=&quot;virtual&quot;><?= $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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top