• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Please help with MySQL and PHP

iBrightDev

Jay Street
NLC
NLC
i currently have a guestbook script that i wrote from a similar one that i liked. now i am still trying to learn php, so bear with me here. I will try to make this as clear as possible. i have found a way to bring the original text to and edit box if you try to edit the comment, but i cant get it to replace the original text. instead, it posts it right below the original text like a follow up or something. i need it to replace the original text. is someone has a script that i can use to do this, i will give full credit on my site if i use the script.


here is what i have for now in my index.php file

PHP:
<?PHP

// [url]www.methodcomptech.com[/url]

include "functions.php";

if ($sss == 1)
{
	$sm  = array *****smily code goes in here, dont worry about this part*****; 
	$num_smiley = 73;
	for ($nc = 1;$nc <= $num_smiley;$nc++)
		$num[] = "<img src=y_emo/$nc.gif>";
}

$num_entry=mysql_numrows($gb);

$epp = $def_epp;
if (isset($_GET['epp']) and ($_GET['epp'] != ""))
	$epp = $_GET['epp'];

$pg = 1;
if (isset($_GET['pg']) and ($_GET['pg'] != ""))
	$pg = $_GET['pg'];

$tp = ceil($num_entry/$epp);

$start = ($pg-1) * $epp;
$end = $start + $epp;

echo "<html><head><title>$title</title></head><body text=#000000 link=gray alink=gray vlink=gray bgcolor=white><font size=1>";
if ($center != 0)
	echo "<center>";

echo "<table width=$width cellpadding=0 cellspacing=0 border=0><tr><td width=1%><img src=ipei_imgs/blank.gif width=1 height=1></td><td width=96% valign=bottom align=right><font face=arial size=1 color=gray>Page: ";

echo "<a href=index.php?pg=1&epp=$epp>&lt;&lt;</a> | ";

for ($a=$pg-4;$a < $pg;$a++)
{
	if (($a >= 1) and ($a <= $tp))
		echo "<a href=index.php?pg=$a&epp=$epp>$a</a> | ";
}

echo "<b><font size=+1>$pg</font></b>";

for ($b=$pg+1;$b <= $pg+4;$b++)
{
	if (($b >= 1) and ($b <= $tp))
		echo " | <a href=index.php?pg=$b&epp=$epp>$b</a>";
}

echo " | <a href=index.php?pg=$tp&epp=$epp>&gt;&gt;</a>";

echo " of $tp pages.<br><font face=arial size=4 color=gray><a href=index.php?a=view>v<b>i</b>ew</a> / <a href=index.php?a=sign>s<b>i</b>gn</a></font></font></td><td width=3%><img src=ipei_imgs/blank.gif width=1 height=1></td></tr></table><br><br>";

if ($_GET['a'] == "smilies")
{
	echo "<font size=1 face=arial color=gray>Emoticons are &copy; Yahoo!<br>note: not all smilie codes are exactly same as on Yahoo Messenger</font><br><br><table border=1>";
	for ($i=0;$i < $num_smiley;$i++)
	{
		echo "<tr><td>$sm[$i]</td><td>$num[$i]</td></tr>";
	}
	echo "</table>";
}
else if ($_GET['a'] == "process_delete")
{
	if ($_POST[password] == $pw)
	{
		$DQuery = "DELETE FROM `$table` WHERE `entrynum` = $_POST[e]";
		mysql_query($DQuery);
		echo "<font size=2 face=arial>Entry $_POST[e] Deleted.<br><br></font>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "process_comment")
{
	if ($_POST[password] == $pw)
	{
		$cmttime = date("Y-m-d H:i:s");
		$querya="UPDATE `$table` SET `comment` = '$_POST[comment]',`comment_date` = '$cmttime' WHERE `entrynum` = '$_POST[e]'";
		mysql_query($querya);
		echo "<font size=2 face=arial>Comment added for entry $_POST[e].<br><br></font>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "edit")
{
	if ($_POST[password] == $pw)
	{
		$query="SELECT * FROM `$table` WHERE 1 AND `entrynum` = $_POST[e]";
		$entryfile=mysql_query($query);
		$tip = mysql_result($entryfile,0,"ip");
		$tisp = mysql_result($entryfile,0,"res_ip");
		$original_cmt = mysql_result($entryfile,0,"msg");
	
		echo "<font size=1 color=gray face=arial>Edit Original Message:<br></font><form action=index.php?a=process_comment method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><TEXTAREA name=\"comment\" rows=12 cols=45>$original_cmt</TEXTAREA><br><input type=submit name=submit value=\"Edit Comment\" mysql_query($DQuery)></form><hr width=$width><br></font>";

//////////////////////


		echo "<font size=1 color=gray face=arial>Edit Original Message:<br></font><form action=index.php?a=process_comment method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><table cellspacing=3 cellpadding=3 border=0>
	<tr><td><TEXTAREA name=\"msg\" rows=12 cols=45>$original_cmt</TEXTAREA></td></tr>
	</table><br><input type=submit name=submit value=\"Edit Comment\"></form><br>";


//////////////////////

		echo "<font size=2 face=arial>IP: $tip<br>Resolved IP: $tisp<br>";

		echo "<font size=2 face=arial><br>Original Message:<br>";
		
		displayEntry(mysql_result($entryfile,0,"name"),mysql_result($entryfile,0,"msg"),mysql_result($entryfile,0,"comment"),mysql_result($entryfile,0,"email"),mysql_result($entryfile,0,"homepage"),convert_datetime(mysql_result($entryfile,0,"date"), "F j Y"),1,mysql_result($entryfile,0,"entrynum"));

		echo "<br><hr width=$width><font size=1 color=red face=arial>Delete:<br></font><form action=index.php?a=process_delete method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><input type=submit name=submit value=\"Delete entry #$_POST[e], CANNOT BE UNDONE\"></form>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "login")
{
	$form = "<br><form action=index.php?a=edit method=POST><table cellspacing=3 cellpadding=3 border=0>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>password</font></td><td><input type=password name=\"password\" size=26><input type=hidden name=\"e\" value=\"$_GET[e]\"></td></tr>
	<tr><td>&nbsp;</td><td><input type=submit name=submit value=\"Login to edit entry #$_GET[e]\"></td></tr>
	</table></form><br>";

	echo $form;
}
else if ($_GET['a'] == "process")
{
	if (($_POST[name] == "") or ($_POST[msg] == ""))
		echo "<font size=2 face=arial>Missing Field(s): please input a name and a message<br><br></font>";
	else {
	$entrytime = date("Y-m-d H:i:s");
	$userIP = getenv("REMOTE_ADDR");
	$userISP = gethostbyaddr($userIP);

	$in_query = "INSERT INTO `$table` VALUES ('','$_POST[name]','$_POST[email]','$_POST[homepage]','','$_POST[msg]','$entrytime','','','$userIP','$userISP','1')";
	mysql_query($in_query);

	echo "<font size=2 face=arial>Thank you for posting $_POST[name]!<br><br></font>";
	}
}
else if ($_GET['a'] == "sign")
{
	$form = "<br><form action=index.php?a=process method=POST><table cellspacing=3 cellpadding=3 border=0>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>name</font></td><td><input type=text name=\"name\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>email</font></td><td><input type=text name=\"email\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>homepage</font></td><td><input type=text name=\"homepage\" value=\"http://\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>message</font></td><td><TEXTAREA name=\"msg\" rows=6 cols=30></TEXTAREA></td></tr>
	<tr><td>&nbsp;</td><td><input type=submit name=submit value=Post></td></tr></table></form>";

	if ($sss == 1)
		$form = $form . "<center><a href=index.php?a=smilies target=_blank>smilies help</a></center><br>";

	displayEntry("Sign Guestbook",$form,"",NULL,NULL,NULL,0,NULL);
}
else if ($num_entry == 0)
{
	echo "<font size=2 face=arial>The guestbook is empty.<br><br></font>";
}
else
{
	for ($c=$start;$c < $end;$c++)
	{
		if (($c >= 0) and ($c < $num_entry))
		{
			displayEntry(mysql_result($gb,$c,"name"),mysql_result($gb,$c,"msg"),mysql_result($gb,$c,"comment"),mysql_result($gb,$c,"email"),mysql_result($gb,$c,"homepage"),convert_datetime(mysql_result($gb,$c,"date"), "F j Y"),1,mysql_result($gb,$c,"entrynum"));
		}
	}
}
cleanup();

echo "</center><br><br></font></body><comment><!-- Method Comptech Technologies Guestbook - www.methodcomptech.com | emoticons are copyright by Yahoo! --></comment></html>";
?>
--------------------------------------

if you can find the error in that, i would greatly appreciate it. you will notice in the code that i do have it displaying the textbox with the original message. the top one will be changed to not do that anymore and will be a textbox to have followup responces written by the me to anyones posting, but the second box will need to display the original text so that it can be edited. second though, you can remove the first text box from the code, and keep the second since this is going to be a script now being used for a guestbook anymore. it will be used for me to post messages directly from my site and displayed on a recent news link page for my site. please help. thanks in advance
 
Last edited:
p.s. if you need t o see the code for the other php files, let me know, but you should need to i dont think.

sorry for the double post, but it would not let me edit it for some reason.
 
it has php tags. <?php > if you are talking about something other than that, i am not sure what you mean.
 
Can help you

Hey there

I can help you out either make a guestbook from scratch OR fix this one.

However in order to see why the posts are being insterted then updated I would need to see all the codes and the database structure which is a more detailed process.

BUT there is 1 thing I would like to advise you:
When trying to UPDATE comments or bigger amounts of text and place them into a MySQL database you should use the addslashes() function to make the update/insert possible.

Here's YOUR code:
PHP:
UPDATE `$table` SET `comment` = '$_POST[comment]'

Here's what it should look like:
PHP:
UPDATE `$table` SET `comment` = '".addslashes($_POST[comment])."'

The REASON is that when $_POST[comments] will get a value like the word: can't it will bypass the ' sign and return a MySQL Error visible with an extra
PHP:
echo mysql_error();
line. When you put the variable to be insterted between addslashes() it will be then correctly added/updated to the database table without any error.

Hope this helps
 
it will be helpfull, but before i test it i was wondering if that is to update the comment from the original to whatever is typed later, or if it is just going to add it in like a followup. i dont want it to just add it in. i need it to completely change or update the current message posted. that way, i can choose to add more postings, or change and update the ones i have already there. i would also like to make it to where i add some sort of code to each one of my pages on my site that will give a sort of blurb, couple sentences, about whatever i post about, with a link saying, "click here to read more". is this possible? either post here, or PM me. thanks for your help. and thanks in advance if you can tell me how to do the rest of this.
 
Yes

Yeap

All that you described earlier is doeable in PHP nonetheless.

Just to make 1 thing clear... a mysql/PHP
PHP:
mysql_query("UPDATE....")
statement will NOT do anything else then UPDATE the ENTIRE content of a table ROW. It will NEVER INSERT a new row as your case is...

So the error is somewhere in other script files as I can see it since I saw that the update was made whatever correctly in the code you provided.

Please PM me with more info on where is the script installed and I could try to have a look over all the files and try to fix it to your requirements.

OR if you have any amount of $$ to spend, you could describe what your guestbook should be like and I could build a totally custom one from scratch.


Thanks
 
Last edited:
i am still not sure what you are talking about. it is in the BBcode php tags, but whatever. thanks for the help, i guess?
 
i tried this

PHP:
<?PHP

// www.methodcomptech.com

include "functions.php";

if ($sss == 1)
{
	$sm  = array (";))",":((",";;)",">:D<",";)","\\:D/",":-/",":x",":\">",":P",":-*","=((",":o","x(",":>","B-)","#:-S",":-S",">:)",":(|)",":))",":|","/:)","=))","O:)",":-B","=;","I-|","8-|","L-)",":-&",":-$","[-(",":O)","8-}","<:-P","(:-|","=P~",":-?","#-o","=D>",":-ss","@-)",":^o",":-w",":-<",">:p","<):)",":@)","3:-O",":(","~8>","@};-","%%-",":-j","(~~)","^:)^","[-x","8-x","=:)",">-)",":-L","[-O<","$-)",":-\"","B-(",":)>-",":-@",":D",">:/",":)",":p",":O"); 
	$num_smiley = 73;
	for ($nc = 1;$nc <= $num_smiley;$nc++)
		$num[] = "<img src=y_emo/$nc.gif>";
}

$num_entry=mysql_numrows($gb);

$epp = $def_epp;
if (isset($_GET['epp']) and ($_GET['epp'] != ""))
	$epp = $_GET['epp'];

$pg = 1;
if (isset($_GET['pg']) and ($_GET['pg'] != ""))
	$pg = $_GET['pg'];

$tp = ceil($num_entry/$epp);

$start = ($pg-1) * $epp;
$end = $start + $epp;

echo "<html><head><title>$title</title></head><body text=#000000 link=gray alink=gray vlink=gray bgcolor=white><font size=1>";
if ($center != 0)
	echo "<center>";

echo "<table width=$width cellpadding=0 cellspacing=0 border=0><tr><td width=1%><img src=ipei_imgs/blank.gif width=1 height=1></td><td width=96% valign=bottom align=right><font face=arial size=1 color=gray>Page: ";

echo "<a href=index.php?pg=1&epp=$epp>&lt;&lt;</a> | ";

for ($a=$pg-4;$a < $pg;$a++)
{
	if (($a >= 1) and ($a <= $tp))
		echo "<a href=index.php?pg=$a&epp=$epp>$a</a> | ";
}

echo "<b><font size=+1>$pg</font></b>";

for ($b=$pg+1;$b <= $pg+4;$b++)
{
	if (($b >= 1) and ($b <= $tp))
		echo " | <a href=index.php?pg=$b&epp=$epp>$b</a>";
}

echo " | <a href=index.php?pg=$tp&epp=$epp>&gt;&gt;</a>";

echo " of $tp pages.<br><font face=arial size=4 color=gray><a href=index.php?a=view>v<b>i</b>ew</a> / <a href=index.php?a=sign>s<b>i</b>gn</a></font></font></td><td width=3%><img src=ipei_imgs/blank.gif width=1 height=1></td></tr></table><br><br>";

if ($_GET['a'] == "smilies")
{
	echo "<font size=1 face=arial color=gray>Emoticons are &copy; Yahoo!<br>note: not all smilie codes are exactly same as on Yahoo Messenger</font><br><br><table border=1>";
	for ($i=0;$i < $num_smiley;$i++)
	{
		echo "<tr><td>$sm[$i]</td><td>$num[$i]</td></tr>";
	}
	echo "</table>";
}
else if ($_GET['a'] == "process_delete")
{
	if ($_POST[password] == $pw)
	{
		$DQuery = "DELETE FROM `$table` WHERE `entrynum` = $_POST[e]";
		mysql_query($DQuery);
		echo "<font size=2 face=arial>Entry $_POST[e] Deleted.<br><br></font>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "process_comment")
{
	if ($_POST[password] == $pw)
	{
		$cmttime = date("Y-m-d H:i:s");
		$querya="UPDATE `$table` SET `comment` = '".addslashes($_POST[comment])."',`comment_date` = '$cmttime' WHERE `entrynum` = '$_POST[e]'";
		mysql_query($querya);
		echo "<font size=2 face=arial>Comment added for entry $_POST[e].<br><br></font>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "edit")
{
	if ($_POST[password] == $pw)
	{
		$query="SELECT * FROM `$table` WHERE 1 AND `entrynum` = $_POST[e]";
		$entryfile=mysql_query($query);
		$tip = mysql_result($entryfile,0,"ip");
		$tisp = mysql_result($entryfile,0,"res_ip");
		$original_cmt = mysql_result($entryfile,0,"msg");

//////////firt text box displayed (needs to be for follow up comments/////////////
	
		echo "<font size=1 color=gray face=arial>Edit Original Message:<br></font><form action=index.php?a=process_comment method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><TEXTAREA name=\"comment\" rows=12 cols=45>$original_cmt</TEXTAREA><br><input type=submit name=submit value=\"Edit Comment\" mysql_query($DQuery)></form><hr width=$width><br></font>";

///////////////////////////end of first text box/////////////////////////////////

////this is the second text box displayed (needed to change entire comment)//////


		echo "<font size=1 color=gray face=arial>Edit Original Message:<br></font><form action=index.php?a=process_comment method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><table cellspacing=3 cellpadding=3 border=0>
	<tr><td><TEXTAREA name=\"msg\" rows=12 cols=45>$original_cmt</TEXTAREA></td></tr>
	</table><br><input type=submit name=submit value=\"Edit Comment\"></form><br>";


//////////////////////////////end of the second box displayed////////////////////

		echo "<font size=2 face=arial>IP: $tip<br>Resolved IP: $tisp<br>";

		echo "<font size=2 face=arial><br>Original Message:<br>";
		
		displayEntry(mysql_result($entryfile,0,"name"),mysql_result($entryfile,0,"msg"),mysql_result($entryfile,0,"comment"),mysql_result($entryfile,0,"email"),mysql_result($entryfile,0,"homepage"),convert_datetime(mysql_result($entryfile,0,"date"), "F j Y"),1,mysql_result($entryfile,0,"entrynum"));

		echo "<br><hr width=$width><font size=1 color=red face=arial>Delete:<br></font><form action=index.php?a=process_delete method=POST><input type=hidden name=\"password\" value=\"$_POST[password]\"><input type=hidden name=\"e\" value=\"$_POST[e]\"><input type=submit name=submit value=\"Delete entry #$_POST[e], CANNOT BE UNDONE\"></form>";
	}
	else
		echo "<font size=2 face=arial>Invalid Password<br><br></font>";
}
else if ($_GET['a'] == "login")
{
	$form = "<br><form action=index.php?a=edit method=POST><table cellspacing=3 cellpadding=3 border=0>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>password</font></td><td><input type=password name=\"password\" size=26><input type=hidden name=\"e\" value=\"$_GET[e]\"></td></tr>
	<tr><td>&nbsp;</td><td><input type=submit name=submit value=\"Login to edit entry #$_GET[e]\"></td></tr>
	</table></form><br>";

	echo $form;
}
else if ($_GET['a'] == "process")
{
	if (($_POST[name] == "") or ($_POST[msg] == ""))
		echo "<font size=2 face=arial>Missing Field(s): please input a name and a message<br><br></font>";
	else {
	$entrytime = date("Y-m-d H:i:s");
	$userIP = getenv("REMOTE_ADDR");
	$userISP = gethostbyaddr($userIP);

	$in_query = "INSERT INTO `$table` VALUES ('','$_POST[name]','$_POST[email]','$_POST[homepage]','','$_POST[msg]','$entrytime','','','$userIP','$userISP','1')";
	mysql_query($in_query);

	echo "<font size=2 face=arial>Thank you for posting $_POST[name]!<br><br></font>";
	}
}
else if ($_GET['a'] == "sign")
{
	$form = "<br><form action=index.php?a=process method=POST><table cellspacing=3 cellpadding=3 border=0>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>name</font></td><td><input type=text name=\"name\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>email</font></td><td><input type=text name=\"email\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>homepage</font></td><td><input type=text name=\"homepage\" value=\"http://\" size=26></td></tr>
	<tr><td valign=top align=right><font size=2 face=\"$font\" color=$fcolor>message</font></td><td><TEXTAREA name=\"msg\" rows=6 cols=30></TEXTAREA></td></tr>
	<tr><td>&nbsp;</td><td><input type=submit name=submit value=Post></td></tr></table></form>";

	if ($sss == 1)
		$form = $form . "<center><a href=index.php?a=smilies target=_blank>smilies help</a></center><br>";

	displayEntry("Sign Guestbook",$form,"",NULL,NULL,NULL,0,NULL);
}
else if ($num_entry == 0)
{
	echo "<font size=2 face=arial>The guestbook is empty.<br><br></font>";
}
else
{
	for ($c=$start;$c < $end;$c++)
	{
		if (($c >= 0) and ($c < $num_entry))
		{
			displayEntry(mysql_result($gb,$c,"name"),mysql_result($gb,$c,"msg"),mysql_result($gb,$c,"comment"),mysql_result($gb,$c,"email"),mysql_result($gb,$c,"homepage"),convert_datetime(mysql_result($gb,$c,"date"), "F j Y"),1,mysql_result($gb,$c,"entrynum"));
		}
	}
}
cleanup();

echo "</center><br><br></font></body><comment><!-- Method Comptech Technologies Guestbook - www.methodcomptech.com | emoticons are copyright by Yahoo! --></comment></html>";
?>

but it still didnt work with that update. if you have more suggestiong, please let me know
 
Last edited:
here is the code for the functions.php files too. it may help

PHP:
<?PHP

// www.methodcomptech.com

include "config.php";

function Smile($text)
{
	global $sm,$num;
   	return str_replace($sm, $num, $text);
}

function spaceout($input,$len)
{ 
 $l = 0; 
 $output = ""; 
 for ($i = 0; $i < strlen($input); $i++) { 
  $char = substr($input,$i,1); 
  if ($char != " ") { $l++; } else { $l = 0; } 
  if ($l == $len) { $l = 0; $output .= " "; } 
  $output .= $char; 
 } 
 return($output); 
}

function breaktxt($stringtext)
{
global $width,$sss;
$limit = ($width - 31)/14;
$limit = ceil($limit);
$stringtext = str_replace("\n", " <br>", $stringtext);
$stringtext = str_replace("<script", "&lt;script", $stringtext);
$stringtext = str_replace("<pre", "&lt;pre", $stringtext);
$stringtext = str_replace("<iframe", "&lt;iframe", $stringtext);
$stringtext = spaceout($stringtext, $limit);
if ($sss == 1)
	return Smile($stringtext);
else
	return $stringtext;
}

function convert_datetime($datestamp, $format)
{

    if ($datestamp!=0) {

        list($date, $time)=split(" ", $datestamp);

        list($year, $month, $day)=split("-", $date);

        list($hour, $minute, $second)=split(":", $time);

        $stampeddate=mktime($hour,$minute,$second,$month,$day,$year);

        $datestamp=date($format,$stampeddate);

        return $datestamp;
    }

}

function displayEntry ($name,$msg,$comment,$eml,$hp,$entrytime,$br,$entrynum)
{
	global $hptarget,$width,$font,$fcolor,$fsize;
	$topborder = $width - 67;
	$botborder = $width - 31;
	$textwidth = $width - 31;
	$name_res = substr($name,0,$textwidth/9);
	$name_res = str_replace("<","&lt;",$name_res);

	$entryinfo = $entrytime;
	if ($entrynum != NULL)
		$entryinfo = $entryinfo . " ($entrynum) <a href=index.php?a=login&e=$entrynum>e</a>";
	
	echo "<table width=$width border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td><img src=ipei_imgs/top_left_cor.gif width=15 height=25></td>";
	echo "<td width=$topborder valign=center background=ipei_imgs/top_border.gif><img src=ipei_imgs/blank.gif width=$topborder height=1><br><font size=2 face=arial color=black><b> $name_res</b></font></td>";

	if ($eml == "")
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/email_less.gif width=19 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"mailto:$eml\"><img src=ipei_imgs/email.gif width=19 height=25 border=0 alt=Email></a></td>";
	
	if (($hp == "") or ($hp == "http://"))
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/homepage_less.gif width=17 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"$hp\" target=$hptarget><img src=ipei_imgs/homepage.gif width=17 height=25 border=0 alt=Homepage></a></td>";

	echo "<td><img src=ipei_imgs/top_right_cor.gif width=16 height=25></td></tr>";
	echo "<tr><td background=ipei_imgs/left_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td>";

	echo "<td colspan=3 valign=top bgcolor=#FFFFFF width=$textwidth><font face=\"$font\" color=$fcolor size=$fsize><img src=ipei_imgs/blank.gif width=1 height=6><br>";
	if ($br == 1)
		echo breaktxt($msg);
	else
		echo $msg;
	echo "<br><img src=ipei_imgs/blank.gif width=1 height=4><br><table width=100% cellpadding=0 cellspacing=0 border=0><tr><td width=100% align=right><font color=gray size=1 face=arial><i>$entryinfo</i></font></td></tr></table>";
	if ($comment != "")
	{
		echo "<table width=100% cellspacing=0 cellpadding=0><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table><font size=1 color=GRAY> &nbsp; &nbsp; follow up</font><br><table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor=#CACACA><img src=ipei_imgs/blank.gif height=1></td></tr><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table>";
		if ($br == 1)
			echo breaktxt($comment);
		else
			echo $comment;
		
	}
	echo "</font></td><td background=ipei_imgs/right_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td></tr>";
	
	echo "<tr><td><img src=ipei_imgs/bot_left_cor.gif width=15 height=18></td>";
	echo "<td colspan=3 background=ipei_imgs/bot_border.gif width=$botborder><img src=ipei_imgs/blank.gif width=$botborder height=1></td>";
	echo "<td><img src=ipei_imgs/bot_right_cor.gif width=16 height=18></td></tr></table>";
	echo "<img src=ipei_imgs/blank.gif width=1 height=5><br>\r\n";	

}

function cleanup()
{
mysql_close();
echo "<br><br><font face=arial size=1>&nbsp; &nbsp; ";
global $home;
if ($home != "")
	echo "<font size=+1><a href=\"$home\">home</a> </font>| ";
echo "<a href=http://www.methodcomptech.com/mctgb/index.php?a=view target=_self>Method Computer Technologies</a></font>";
}

?>
 
Could you post a censored version of config.php? Do not post your passwords, username, or host name, unless it is localhost. Replace them with ******* Example config.php.inc file:

PHP:
<?
$host="localhost";
$user="******";
$pass="******";
$db="dbname";
?>
 
Last edited:
i hope that those 2 files will help. you can view the guestbook at my site http://www.methodcomptech.com and click the view feedback link. this script will NOT be used for a guestbook in the future though. it will be used as a sort of current news page. you can see how the script is pullng the info to the 2 textboxes if you click on the small (e) link at the bottom of one of the entries and type cometech for the password as a default untill this script is done. thans for any help in advance. i appreciate this very much guys. you are all truley the best. :)

i will post the config in the next posting. give me a min. i dont care about the user name and pw though. i already changed it for this exercise anyways. tahks. give me a sec Tree
 
Last edited:
config.php

PHP:
<?PHP

// www.methodcomptech.com

$server = 'localhost';
$database = 'method_pei3';
$username = '*********';
$password = '*********';
$table="*********";



// GUESTBOOK SETTINGS

// guestbook admin password
$pw = '*********';

// your homepage url, leave blank if you don't have one
$home = "http://www.methodcomptech.com/index.html";

// guestbook title
$title = "-= Method Computer Technologies =- Guestbook";

// number of entries per page
$def_epp = 10;

// width of guestbook entry boxes (in pixels)
$width = 600;

// entry font name
$font = "Arial";

// entry font color
$fcolor = "black";

// entry font size (1-7)
$fsize = 2;

// centering, 1 = on, 0 = off
$center = 1;

// window target for opening guest homepages
$hptarget = "_blank";

// smilies, 1 = on, 0 = off
$sss = 1;








// OPENNING DB CONNECTION

mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Database Does Not Exist");
$query="SELECT * FROM `$table` ORDER BY `entrynum` DESC";
$gb=mysql_query($query);



?>
 
Last edited:
functions.php

PHP:
<?PHP

// www.methodcomptech.com

include "config.php";

function Smile($text)
{
	global $sm,$num;
   	return str_replace($sm, $num, $text);
}

function spaceout($input,$len)
{ 
 $l = 0; 
 $output = ""; 
 for ($i = 0; $i < strlen($input); $i++) { 
  $char = substr($input,$i,1); 
  if ($char != " ") { $l++; } else { $l = 0; } 
  if ($l == $len) { $l = 0; $output .= " "; } 
  $output .= $char; 
 } 
 return($output); 
}

function breaktxt($stringtext)
{
global $width,$sss;
$limit = ($width - 31)/14;
$limit = ceil($limit);
$stringtext = str_replace("\n", " <br>", $stringtext);
$stringtext = str_replace("<script", "&lt;script", $stringtext);
$stringtext = str_replace("<pre", "&lt;pre", $stringtext);
$stringtext = str_replace("<iframe", "&lt;iframe", $stringtext);
$stringtext = spaceout($stringtext, $limit);
if ($sss == 1)
	return Smile($stringtext);
else
	return $stringtext;
}

function convert_datetime($datestamp, $format)
{

    if ($datestamp!=0) {

        list($date, $time)=split(" ", $datestamp);

        list($year, $month, $day)=split("-", $date);

        list($hour, $minute, $second)=split(":", $time);

        $stampeddate=mktime($hour,$minute,$second,$month,$day,$year);

        $datestamp=date($format,$stampeddate);

        return $datestamp;
    }

}

function displayEntry ($name,$msg,$comment,$eml,$hp,$entrytime,$br,$entrynum)
{
	global $hptarget,$width,$font,$fcolor,$fsize;
	$topborder = $width - 67;
	$botborder = $width - 31;
	$textwidth = $width - 31;
	$name_res = substr($name,0,$textwidth/9);
	$name_res = str_replace("<","&lt;",$name_res);

	$entryinfo = $entrytime;
	if ($entrynum != NULL)
		$entryinfo = $entryinfo . " ($entrynum) <a href=index.php?a=login&e=$entrynum>e</a>";
	
	echo "<table width=$width border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td><img src=ipei_imgs/top_left_cor.gif width=15 height=25></td>";
	echo "<td width=$topborder valign=center background=ipei_imgs/top_border.gif><img src=ipei_imgs/blank.gif width=$topborder height=1><br><font size=2 face=arial color=black><b> $name_res</b></font></td>";

	if ($eml == "")
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/email_less.gif width=19 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"mailto:$eml\"><img src=ipei_imgs/email.gif width=19 height=25 border=0 alt=Email></a></td>";
	
	if (($hp == "") or ($hp == "http://"))
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/homepage_less.gif width=17 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"$hp\" target=$hptarget><img src=ipei_imgs/homepage.gif width=17 height=25 border=0 alt=Homepage></a></td>";

	echo "<td><img src=ipei_imgs/top_right_cor.gif width=16 height=25></td></tr>";
	echo "<tr><td background=ipei_imgs/left_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td>";

	echo "<td colspan=3 valign=top bgcolor=#FFFFFF width=$textwidth><font face=\"$font\" color=$fcolor size=$fsize><img src=ipei_imgs/blank.gif width=1 height=6><br>";
	if ($br == 1)
		echo breaktxt($msg);
	else
		echo $msg;
	echo "<br><img src=ipei_imgs/blank.gif width=1 height=4><br><table width=100% cellpadding=0 cellspacing=0 border=0><tr><td width=100% align=right><font color=gray size=1 face=arial><i>$entryinfo</i></font></td></tr></table>";
	if ($comment != "")
	{
		echo "<table width=100% cellspacing=0 cellpadding=0><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table><font size=1 color=GRAY> &nbsp; &nbsp; follow up</font><br><table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor=#CACACA><img src=ipei_imgs/blank.gif height=1></td></tr><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table>";
		if ($br == 1)
			echo breaktxt($comment);
		else
			echo $comment;
		
	}
	echo "</font></td><td background=ipei_imgs/right_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td></tr>";
	
	echo "<tr><td><img src=ipei_imgs/bot_left_cor.gif width=15 height=18></td>";
	echo "<td colspan=3 background=ipei_imgs/bot_border.gif width=$botborder><img src=ipei_imgs/blank.gif width=$botborder height=1></td>";
	echo "<td><img src=ipei_imgs/bot_right_cor.gif width=16 height=18></td></tr></table>";
	echo "<img src=ipei_imgs/blank.gif width=1 height=5><br>\r\n";	

}

function cleanup()
{
mysql_close();
echo "<br><br><font face=arial size=1>&nbsp; &nbsp; ";
global $home;
if ($home != "")
	echo "<font size=+1><a href=\"$home\">home</a> </font>| ";
echo "<a href=http://www.methodcomptech.com/mctgb/index.php?a=view target=_self>Method Computer Technologies</a></font>";
}

?>
 
i hope all these files can help you resolve my issure. please forgive the double post of the functions.php file. i forgot that i already posted it and dont know how to remove one of the postings.
 
Back
Top