Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

After filling my form I want a message like "Thanks for filling my Guestbook"

Hi,

I have this PHP script from the net.
Now I want a message after filling in the form.

How to get only "Thanks for filling in my guestbook!"

Here is my script:
******************* Start Code *******************
<?php
// open database connection
include ("config.php");
// check if the form is submitted
if(isset($_POST['go']))
{
      $name = $_POST['name'];
      $email = $_POST['email'];
      $url = $_POST['website'];
      $message = $_POST['message'];
      $date = date("Y-m-d");
      $country = $_POST['country'];
      // empty the url if only default value
      if($url == '')
      {
            $url = '';
      }
      
      $name = htmlspecialchars($name);
      $email = htmlspecialchars($email);
      $message = htmlspecialchars($message);
      
      // add the values to an array
      
      // name
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($name) : $name;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`GuestName`"] = $theValue;
      
      // email
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($email) : $email;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`GuestEmail`"] = $theValue;
      
      // url
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($url) : $url;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`GuestURL`"] = $theValue;
      
      // message
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($message) : $message;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`GuestMessage`"] = $theValue;
      
      // date entry
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($date) : $date;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`GuestEntry`"] = $theValue;
      
      // Country
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($country) : $country;
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`CountryId`"] = $theValue;
      
      // insert into database
      $strsql = "INSERT INTO `gb_myphpguest` (";
      $strsql .= implode(",", array_keys($fieldList));
      $strsql .= ") VALUES (";
      $strsql .= implode(",", array_values($fieldList));
      $strsql .= ")";
      mysql_query($strsql, $ServerConnect) or die(mysql_error());
      // send email to admin
      // change the email here to your desired one
      $admin_email = "webmaster@scheerkoppen.nl";
      $msgtitle = $name . " vulde het gastenbook in.";
    $msgcontent = $message;
      mail($admin_email, $msgtitle, $msgcontent,"From:" . $email ."\n");
      header('Location:'.$_SERVER['REQUEST_URI']);
      exit;
      
}
?>
<?php
// replace smileys and bad word filtering
function creplace($msg)
{
      // smileys
      $msg = str_replace(":)", "<img src='smileys/smile.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace(":(", "<img src='smileys/sad.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace(":p", "<img src='smileys/tongue.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace(":D", "<img src='smileys/biggrin.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace(":@", "<img src='smileys/mad.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace(":0", "<img src='smileys/eek.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace(":S", "<img src='smileys/confused.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace(";)", "<img src='smileys/wink.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace("=blush", "<img src='smileys/blush.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace("=boggle", "<img src='smileys/boggle.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace("=cool", "<img src='smileys/cool.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace("=huh", "<img src='smileys/huh.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace("=notsure", "<img src='smileys/notsure.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace("=ooh", "<img src='smileys/ooh.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace("=rolleyes", "<img src='smileys/rolleyes.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace("=sleep", "<img src='smileys/sleep.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace("=stress", "<img src='smileys/stress.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace("=tired", "<img src='smileys/tired.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace("=urgh", "<img src='smileys/urgh.gif' alt=':)' align='absbottom'>", $msg);
        $msg = str_replace("=worry", "<img src='smileys/worry.gif' alt=':(' align='absbottom'>", $msg);
        $msg = str_replace("=lol", "<img src='smileys/icon_lol.gif' alt=':p' align='absbottom'>", $msg);
      $msg = str_replace("=razz", "<img src='smileys/icon_razz.gif' alt=':p' align='absbottom'>", $msg);

      // bbcode
      $msg = str_replace("[B]", "<strong>", $msg);
      $msg = str_replace("[/B]", "</strong>", $msg);
      $msg = str_replace("[I]", "<em>", $msg);
      $msg = str_replace("[/I]", "</em>", $msg);
      $msg = str_replace("[U]", "<u>", $msg);
      $msg = str_replace("[/U]", "</u>", $msg);
      $msg = str_replace("[LI]", "<li>", $msg);
      $msg = str_replace("[/LI]", "</li>", $msg);
            
      // bad word filter
      // add as many bad words as you can
        $msg = str_replace("bad", "*", $msg);
      $msg = str_replace("shit", "*", $msg);
      $msg = str_replace("bitch", "*", $msg);
      $msg = str_replace("atay", "*", $msg);
      $msg = str_replace("fuck", "*", $msg);
      $msg = str_replace("sex", "*", $msg);
      $msg = str_replace("ugly", "*", $msg);
      $msg = str_replace("hate", "*", $msg);
      $msg = str_replace("hatred", "*", $msg);
        return $msg;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Scheerkoppen Klanten reacties</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
function checkForm()
{
      
      var gname, gwebsite, gmessage;
      with(window.document.gb_myphpguestform)
      {
            gname = name;
            gwebsite = website;
            gmessage = message;
      }
      if(gname.value == '')
      {
            alert('Vul alstublieft uw naam in!');
            gname.focus;
            return false;
      }
      else if(gwebsite.value == '')
      {
            alert('Vul alstublieft uw woonplaats in!');
            gwebsite.focus;
            return false;
      }
      else if(gmessage.value == '')
      {
            alert('Vul alstublieft uw reactie in!');
            gmessage.focus;
            return false;
      }
      else
      {
            return true;
      }
}
function addsmiley(code)
{
      var pretext = document.gb_myphpguestform.message.value;      
      this.code = code;
    document.gb_myphpguestform.message.value = pretext + code;
}
</script>
</head>
<body>
<?php
if(!isset( $_GET ['page' ]))
{
      $page =1;
}
else
{
       $page =$_GET ['page' ];
}
// Define the number of results per page
$max_results = 0;
// Figure out the limit for the query based on the current page number.
$from = (( $page *$max_results ) - $max_results );
// Perform MySQL query on only the current page number's results
$strsql = "SELECT * FROM gb_myphpguest ORDER BY GuestId DESC LIMIT $from, $max_results" ;
$result = mysql_query($strsql, $ServerConnect);
$num_rows = mysql_num_rows($result);

//if($num_rows == 0)
$num_rows = 0;
if($num_rows == 0)
{
?>
      <div class="headingfont"><p class="alignmentcenter"><br><br></p></div>
<?php
}
else
{
?>
      <table width="400" cellspacing="0" cellpadding="1" align="center" bgcolor="#333333" style="border:1px solid #333333;">
            <tr>
<!--
                  <td align="center" valign="middle" width="300"><div class="headingfont"><a href="admin.php"><img src="images/login.gif" align="left" border="0"></a> Reacties</div></td>
 -->
                  <td valign="middle" align="right"><a href="#signin"><div class="headingfont">Plaats uw reactie, klik hier</div></a></td>
            </tr>
<?php
      while($row = mysql_fetch_array($result))
      {
            $key = $row['GuestId'];
            $name = $row['GuestName'];
            $email = $row['GuestEmail'];
            $url = $row['GuestURL'];
            $message = $row['GuestMessage'];
            $fmessage = nl2br($message);
            $dateposted = $row['GuestEntry'];
            $country = $row['CountryId'];
            
?>
            <tr>
                  <td class="entryheaders">
                        <?php
                        echo "<b>" .$name . "</b> te <b> " . $url . "</b> op <b> " . $dateposted . "</b> ";
                        $csql = "SELECT * FROM gb_countries WHERE CountryId='". $country . "'";
                        $cresult = mysql_query($csql, $ServerConnect) or die (mysql_error());
                        while($crow = mysql_fetch_array($cresult))
                        {
                              $fcounrty = $crow['Country'];
                              echo "<b>" .$fcounrty . "</b>";
                        }
                        ?>
                  </td>
                  <td class="entryheaders" align="right">
                        <?php
                        if ($email != "")
                        {
                              echo "<a href='mailto:" . $email . "'><img src='images/mail.gif' border='0'></a>&nbsp;";
                        }
                        else
                        {
                              echo  "<img src='images/mail.gif' border='0'>&nbsp;";
                        }
                        if ($url != "")
                        {
                              //echo "<a href='" . $url . "' target='_blank'><img src='images/web.gif' border='0'></a>&nbsp;";
                        }
                        else
                        {
                              //echo  "<img src='images/web.gif' border='0'>&nbsp;";
                        }
                        ?>
                  </td>
            </tr>
            <tr bgcolor="#F0F0EB">
                  <td align="left" valign="top" colspan="2">
                        <?php
                        $themessage = creplace($fmessage);
                        $finalmessage = wordwrap($themessage, 15, "\n", 1);
                        echo $finalmessage. "\n<br><br>";
                        ?>
                  </td>
            </tr>
<?php
      } //end while
} //end if
?>
<?php
// Figure out the total number of results in DB:
$total_results =mysql_result (mysql_query ("SELECT COUNT(*) as Num FROM gb_myphpguest" ), 0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages =ceil ($total_results /$max_results );
?>
      <tr>
            <td class="entryheaders" colspan="2" align="center">
<?php
// Build Previous Link
if( $page >1)
{
      $prev = ( $page -1);
    echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$prev \" ><img src='images/previous.gif' border='0' alt='previous' align='middle'></a>&nbsp;" ;
}

for( $i =1;$i <= $total_pages ;$i ++)
{
    if(( $page ) == $i )
      {
        echo "$i&nbsp;";
      }
      else
      {
            echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$i \" >$i</a>&nbsp;" ;
    }
}
// Build Next Link
if( $page <$total_pages )
{
      $next = ( $page +1);
    echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$next \" ><img src='images/next.gif' border='0' alt='Vorige' align='middle'></a>" ;
}
?>
            </td>
      </tr>
</table>
<form name="gb_myphpguestform" method="post" action="" onSubmit="return checkForm();">
<table width="400" cellspacing="0" cellpadding="3" align="center" bgcolor="#333333" style="border: 1px solid #333333;">
      <tr>
            <td colspan="2" valign="top"><div class="headingfont"><a name="signin">Plaats uw reactie</a></div></td>
      </tr>
      <tr bgcolor="#FFFFFF">
          <td width="100" height="24" valign="middle">Naam:</td>
          <td width="300" valign="top"> <input type="text" name="name" size="35"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
            <td valign="middle">Email (niet verplicht):</td>
            <td valign="top"><input type="text" name="email" size="35"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
            <td valign="middle">Woonplaats:</td>
            <td valign="top"><input type="text" name="website" size="35" value=""></td>
    </tr>
      <tr bgcolor="#FFFFFF">
            <td valign="middle">Land:</td>
            <td valign="top">
                  <select name="country" style="width:203px;">
                  <?php
                  $countryquery = "SELECT * FROM gb_countries";
                  $countryresult = mysql_query($countryquery, $ServerConnect) or die("Failed to execute query" . mysql_error() . ' SQL:' . $countryquery);
                  while($rows = mysql_fetch_array($countryresult))
                  {
                        $key = $rows['CountryId'];
                        $country = $rows['Country'];
                        
                        echo "<option value='". $key. "'>".$country. "</option>";
                  }
                  mysql_free_result($countryresult);
                  mysql_close($ServerConnect);
                  ?>
                  </select>
            </td>
    </tr>
    <tr bgcolor="#FFFFFF">
            <td  valign="middle">Uw reactie:</td>
            <td valign="top">
                  <img src="smileys/smile.gif" alt=":)" border="0" onClick="addsmiley(':)')" style="cursor: pointer;">
                  <img src="smileys/sad.gif" alt=":(" border="0" onClick="addsmiley(':(')" style="cursor: pointer;">
                  <img src="smileys/tongue.gif" alt=":p" border="0" onClick="addsmiley(':p')" style="cursor: pointer;">
                  <img src="smileys/biggrin.gif" alt=":D" border="0" onClick="addsmiley(':D')" style="cursor: pointer;">
                  <img src="smileys/mad.gif" alt=":@" border="0" onClick="addsmiley(':@')" style="cursor: pointer;">
                  <img src="smileys/eek.gif" alt=":0" border="0" onClick="addsmiley(':0')" style="cursor: pointer;">
                  <img src="smileys/confused.gif" alt=":S" border="0" onClick="addsmiley(':S')" style="cursor: pointer;">
                  <img src="smileys/wink.gif" alt=";)" border="0" onClick="addsmiley(';)')" style="cursor: pointer;">
                  <img src="smileys/blush.gif" alt="=blush" border="0" onClick="addsmiley('=blush')" style="cursor: pointer;">
                  <img src="smileys/boggle.gif" alt="=boggle" border="0" onClick="addsmiley('=boggle')" style="cursor: pointer;">
                  <img src="smileys/cool.gif" alt="=cool" border="0" onClick="addsmiley('=cool')" style="cursor: pointer;"><br>
                  <img src="smileys/huh.gif" alt="=huh" border="0" onClick="addsmiley('=huh')" style="cursor: pointer;">
                  <img src="smileys/notsure.gif" alt="=notsure" border="0" onClick="addsmiley('=notsure')" style="cursor: pointer;">
                  <img src="smileys/ooh.gif" alt="=ooh" border="0" onClick="addsmiley('=ooh')" style="cursor: pointer;">
                  <img src="smileys/rolleyes.gif" alt="=rolleyes" border="0" onClick="addsmiley('=rolleyes')" style="cursor: pointer;">
                  <img src="smileys/sleep.gif" alt="=sleep" border="0" onClick="addsmiley('=sleep')" style="cursor: pointer;">
                  <img src="smileys/stress.gif" alt="=stress" border="0" onClick="addsmiley('=stress')" style="cursor: pointer;">
                  <img src="smileys/tired.gif" alt="=tired" border="0" onClick="addsmiley('=tired')" style="cursor: pointer;">
                  <img src="smileys/urgh.gif" alt="=urgh" border="0" onClick="addsmiley('=urgh')" style="cursor: pointer;">
                  <img src="smileys/worry.gif" alt="=worry" border="0" onClick="addsmiley('=worry')" style="cursor: pointer;">
                  <img src="smileys/icon_lol.gif" alt="=lol" border="0" onClick="addsmiley('=lol')" style="cursor: pointer;">
                  <img src="smileys/icon_razz.gif" alt="=razz" border="0" onClick="addsmiley('=razz')" style="cursor: pointer;"><br>
                  
                  <img src="smileys/bold.gif" alt="=razz" border="0" onClick="addsmiley('[B][/B]')" style="cursor: pointer;">
                  <img src="smileys/italic.gif" alt="=razz" border="0" onClick="addsmiley('[I][/I]')" style="cursor: pointer;">
                  <img src="smileys/underline.gif" alt="=razz" border="0" onClick="addsmiley('[U][/U]')" style="cursor: pointer;">
                  <img src="smileys/list.gif" alt="=razz" border="0" onClick="addsmiley('[LI][/LI]')" style="cursor: pointer;">
                  
                  <textarea name="message" rows="7" cols="37"></textarea>
            </td>
    </tr>
      <tr bgcolor="#FFFFFF">
            <td  valign="middle">&nbsp;</td>
            <td valign="top">
                    <input name="reset" type="reset"  value="RESET">
                  <input name="go" type="submit" value="OK">
              </td>
    </tr>
</table>
</form>
</body>
</html>
******************* Endt Code *******************

Thanks!
HP van Hagen
0
WvR
Asked:
WvR
1 Solution
 
jgsemoCommented:
Hi

I think the best way to go is create an html page that says "Thanks for filling in my guestbook!" and name it thanks.html and then on this script on line 68 where is says:

header('Location:'.$_SERVER['REQUEST_URI']);

change that for:

header('Location:thanks.html');
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now