Ask a Question related to Macromedia Flash Data Integration, Design and Development.
-
professorsr #1
Guestbook Help Please
I am currently putting together a web site for my niece that includes a
guestbook (w/php and mysql). For some reason, when you go to the guestbook and
click the view button, some computer connections II have ran into three so far)
cant connect to the database. BUT I created another page that is strictly php
(this page displays the same results as the guestbook) and the results are
displayed correctly - essentially confirming that there is a connection being
made to the database. Also, as I stated before this has only happened on three
computer connections so far, but i can't risk this happening when a visitor
gets to the site once we actually launch this site. the url to the site is as
follows: [url]http://oliviacourtney.net/html/index.html[/url]
Click GUESTBOOK then click VIEW. This should populate the bottom box with
messages from database.
I will post the code
I have removed username and password for obvious reasons
flash actionscript code
this.onEnterFrame = function() {
//shows the amount of messages showed right below the guestbook
//display.startAmount is a variable located inside display mc
//and that is sent to the readGuestbook.php
from = display.startAmount;
to = display.startAmount+5;
//showing is a text field below the guestbook
showing.text = from+" - "+to;
//my way of rounding numbers to nearest tenth:
//display.maxRows is a variable, sent from the php
//it is the maximum amount of messages in the guestbook
temp = display.maxrows;
maxPages = Math.ceil(temp/10)*10;
};
form.onData = function() {
//stuff that happens after information is sent to php:
//sendInfo is a textfield next to the buttons
sendInfo.text = "sent";
//clearing the fields...
form.name = "";
form.location = "";
form.email = "";
form.message = "";
//loading the guestbook again (with the new entry):
//telling the display mc from which mesasge starting should the guestbook be
loaded
display.startAmount = 0;
//NOTE: here we're using "POST" to load variables. That's because we're both
sending
//and receiving information from the php
display.loadVariables("http://oliviacourtney.net/html/readGuestbook.php",
"POST");
sendInfo.text = "receiving";
//let's focus on the first line
display.guestbook.scroll = 1;
};
display.onData = function() {
sendInfo.text = "received";
};
//functions for the buttons
submit.onRelease = function() {
form.loadVariables("http://oliviacourtney.net/html/writeGuestbook.php",
"POST");
sendInfo.text = "sending";
};
view.onRelease = function() {
display.startAmount = 0;
display.loadVariables("http://oliviacourtney.net/html/readGuestbook.php",
"POST");
sendInfo.text = "receiving";
};
next.onRelease = function() {
//trying to make sure here that it doesn't try to load more entries than what
are stored
if ((display.startAmount+5)<maxPages) {
display.startAmount += 5;
display.loadVariables("http://oliviacourtney.net/html/readGuestbook.php",
"POST");
display.guestbook.scroll = 1;
sendInfo.text = "receiving";
}
};
prev.onRelease = function() {
//making sure that we're not trying to view negative entries
if (display.startAmount>0) {
display.startAmount -= 5;
display.loadVariables("http://oliviacourtney.net/html/readGuestbook.php",
"POST");
display.guestbook.scroll = 1;
sendInfo.text = "receiving";
}
};
readGuestbook.php
<?
$host = "mysql4.freehostia.com"; // Name of machine mysql is running on
$user = ""; // Username to access mysql
$pass = ""; // Password to access mysql
$dbname = "zemcou_olivia"; // Name of the database where the guestbook is
$startAmount = $_POST["startAmount"];
$link = @mysql_connect($host, $user, $pass) or die("Could not connect to
database.");
mysql_select_db($dbname, $link) or die("Could not find database $dbname");
$query="SELECT *
FROM guestBook
WHERE view = 'Y'
ORDER BY id DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) :
$name=$row["name"];
$date=$row["date"];
$message=$row["message"];
$output .= "<font color=\"#000000\"><b>$name</b> wrote on $date</font><br>";
$output .= "$message<br>----------<br>";
endwhile;
$query2 = mysql_query("SELECT `id` FROM `guestBook` ORDER BY `id` DESC LIMIT
1")or die("Could not query");
$maxRows = mysql_fetch_row($query2);
$maxRows[0];
print "guestbook=$output&maxrows=$maxRows[0]";
?>
writeGuestbook.php
<?
$host = "mysql4.freehostia.com"; // Name of machine mysql is running on
$user = ""; // Username to access mysql
$pass = ""; // Password to access mysql
$dbname = "zemcou_olivia"; // Name of the database where the guestbook is
$name = $_POST["name"];
$location = $_POST["location"];
$email = $_POST["email"];
$message = $_POST["message"];
//<--- start time
$today = getdate();
$day = $today[mday];
if ($day < 10) {
$day = "0" . $day;
}
$month = $today[mon];
if ($month < 10) {
$month = "0" . $month;
}
$hrs = $today[hours];
if ($hrs < 10) {
$hrs = "0" . $hrs;
}
$mins = $today[minutes];
if ($mins < 10) {
$mins = "0" . $mins;
}
$timeStampTime = $hrs . ":" . $mins;
$timeStampDate = $day . "/" . $month . "/". $today[year];
//end time --->
$link = @mysql_connect($host, $user, $pass) or die("Could not connect to
database.");
mysql_select_db($dbname, $link) or die("Could not find database $dbname");
mysql_query("INSERT INTO guestBook (name,email,message,time,date,location)
VALUES ('$name', '$email', '$message', '$timeStampTime', '$timeStampDate',
'$location')");
?>
messages.php
<?php require_once('../Connections/olivia.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_olivia, $olivia);
$query_Recordset1 = "SELECT * FROM guestBook ORDER BY id DESC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1,
$startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $olivia) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s",
$totalRows_Recordset1, $queryString_Recordset1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1" align="center">
<tr>
<td>id</td>
<td>date</td>
<td>time</td>
<td>name</td>
<td>email</td>
<td>message</td>
<td>location</td>
<td>view</td>
</tr>
<?php do { ?>
<tr>
<td><a href="message_update.php?recordID=<?php echo
$row_Recordset1['id']; ?>"> <?php echo $row_Recordset1['id']; ?> </a>
</td>
<td><?php echo $row_Recordset1['date']; ?> </td>
<td><?php echo $row_Recordset1['time']; ?> </td>
<td><?php echo $row_Recordset1['name']; ?> </td>
<td><?php echo $row_Recordset1['email']; ?> </td>
<td><?php echo $row_Recordset1['message']; ?> </td>
<td><?php echo $row_Recordset1['location']; ?> </td>
<td><?php echo $row_Recordset1['view']; ?> </td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<br />
<table border="0">
<tr>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0,
$queryString_Recordset1); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage,
max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_Recor
professorsr Guest
-
Guestbook Sample
I used Guestbook application sample from adobe. and modified for saving streams. But now streams are saved in an "undefined" folder. Please... -
Guestbook
right basically all i want is that when someone signs the guestbook and its like a bad post or accidental ect ... how can you delete just that 1... -
cookies in guestbook
Hi There, To save name etc. in a guestbookform I try to use cookies, so the user do not have to type these data again each time they want to sign... -
Dhtml GuestBook
I am on free web hosting and not supporting php or any lauguage so is there a dhtml guestbook I can install on my site which don't require any... -
trying to create a guestbook
I am trying to create a guest book using ASP Server Application Error The server has encountered an error while loading an application during the... -
Noelbaland #2
Re: Guestbook Help Please
Hello,
I think this was answered before? All you do is change all the paths in your
actionscript to relative. Because of Flash's sandbox security feature some
servers don't allow access properly.
So instead of
"http://oliviacourtney.net/html/readGuestbook.php", "POST"
change it to
"html/readGuestbook.php", "POST"
Just a thought - if you want to be extra cautious then use the LoadVars
command instead of loadVariables. LoadVars has a onLoad method that checks if
your data is going into Flash or not. More secure and more reliable.
Noelbaland Guest
-



Reply With Quote

