This is what I would like to do.
[list][*]
issue a query to the guestbook table
issue a query to the guestbook_comments table
match the ID from the guestbook table with the ID from the guest_comments table
put an if{}else{} statement in the $guest_block to check if there is a match between two tables ID numbers
then using a ‘while {}’ loop create the entries below the initial post from the guestbook table
this is the function I am writing to carry out this script. I will make the reply creation script later. (hard stuff first) Right now it errors and just displays a blank page. NO Error MSG displays at all
[code=php]
function guest($connection) {
$table_name = “guestbook”;
$table_2 = “guest_comments”;
$r_sql = “SELECT * FROM $table_2 ORDER BY id ASC”;
$r_result = mysql_query($sql,$connection) or die (mysql_error());
$sql = “SELECT * FROM $table_name ORDER BY id DESC”;
$result = mysql_query($sql,$connection) or die (mysql_error());
global $guest_block;
$guest_block = “<table class=”gbook” width=”70%” align=”center” cellpadding=”5″ cellspacing=”0″>”;
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from the array
$user_no = ($row[‘id’]);
$name = ($row[‘name’]);
$date = ($row[‘date’]);
$e_mail = ($row[‘e_mail’]);
$msg = ($row[‘msg’]);
$web_site = ($row[‘web_site’]);
$guest_block .= ”
<tr class=”gb_bar”>
<td colspan=”2″><span class=”title_bar”>$name No: $user_no<br/>$date</span></td>
</tr>
<tr>
<td colspan=”2″ class=”msgblock”><p>$msg</p></td>
</tr>
<tr>
<td colspan=”2″ class=”msgbottom”><span class=”web”><a href=”$web_site” title=”Erie Guestbook”>Favorite Site</a> </span></td>
</tr>”;
//This part is a new edition and doesn’t work yet
if ($result == $r_result) {
while ($row = mysql_fetch_array($r_result)) {
// get individual elements from the Reply array
$r_user_no = ($row[‘r_id’]);
$r_name = ($row[‘r_name’]);
$r_date = ($row[‘r_date’]);
$r_e_mail = ($row[‘r_e_mail’]);
$r_msg = ($row[‘r_msg’]);
$r_web_site = ($row[‘r_web_site’]);
// for testing purposes it only displays the ID for now I will
//end up displayin all the info soon enough
$guest_block .= “<tr><td> </td><td>$r_user_no</td></tr>”;
} else {
$guest_block .= “<tr><td> </td><td> </td></tr>”;
}
}
$guest_block .= “</table>”;
}
And I call the function from this file which has two different functions. One to show the POSTS and FORM and the other function INSERTS the data from FORM and shows just the guest book. this is just the PHP from it since it is the only important part of the document.
[code=php]
<?
require(“listingsfunc2.php”);
if ($_POST[e_mail] == “”) {
ini_set(“display_errors”, “1”);
error_reporting(E_ALL);
// No FORM must have been submited so moving on…
// I want to display guestbook entries also a FORM so they can add an entry
//log the user IP, name of page, User Agent
$page_title = “Guest Book”;
dbconnect();
pagecount($page_title);
//$guest = Works displays fine all the entrys in the guestbook
guest($connection);
//need these variable defined for the form
$date = date(“Y-m-d”);
$address = getenv(“REMOTE_ADDR”);
//start the form that post to this itself
$form_block = ”
<table align=”center” cellspacing=”0″ cellpadding=”20″ class=”form”>
<tr>
<td>
<br/><br/><span class=”lineup”>
<form method=”post” action=”$_SERVER[PHP_SELF]”>
<input type=”hidden” name=”date” value=”$date” />
<input type=”hidden” name=”ip” value=”$address” /><br/>
<label>Name</label><br />
<input type=”text” name=”name” size=”30″ /><br />
<label>Favorite Web Site</label><br />
<input type=”text” name=”web_site” size=”30″ value=”http://www.eriescene.com” /><br />
<label>E-mail Address</label><br />
<input type=”text” name=”e_mail” size=”30″ /><br />
<label>Your Message</label><br />
<textarea name=”msg” rows=”6″ cols=”40″></textarea><br /><br />
<input type=”hidden” name=”op” value=”ds” />
<div align=”center”>
<input name=”submit” type=”submit” value=”Submit Post” />
<input name=”reset” type=”reset” value=”Reset” />
</div>
</form>
</span>
</td>
</tr>
</table>”;
} else {
ini_set(“display_errors”, “1”);
error_reporting(E_ALL);
dbconnect();
//the form was submited properly because the all the fields are filled in
//log the user IP, name of page, User Agent
$page_title = “Guest Book”;
pagecount($page_title);
function sanitize($input)
{
if(get_magic_quotes_gpc())
{
$input = stripslashes($input);
}
return(mysql_real_escape_string($input));
}
//Start INSERT the Results of the Form
//Run Sanitize Function
$name = sanitize($_POST[‘name’]);
$date = ($_POST[‘date’]);
$e_mail = sanitize($_POST[‘e_mail’]);
$msg = sanitize($_POST[‘msg’]);
$web_site = sanitize($_POST[‘web_site’]);
//start, build, and issue the QUERY statment
$table_name = “guestbook”;
$sql = ”
INSERT INTO $table_name VALUES ( ”, ‘$name’, ‘$date’, ‘$e_mail’, ‘$msg’, ‘$ip’, ‘$web_site’)”;
$result = mysql_query($sql,$connection)
or die (‘I cannot connect to the database because: ‘ . mysql_error());
//Connect again to view the database after the new values have been inserted
//Remeber no form this time they allready posted.
guest($connection);
$form_block = “<div align=”center”><span style=”color:green;font-size:12px;”>Thanks for Posting!!</span></div>”;
}
//close the db connection.}
mysql_close($connection);
?>
Like I said I started this and ran it with no success. Can anyone help me with this? I don’t really even know if this is completely possible the way I percieve it.