Hello Everyone.
I am very new to php and have been studying the friends of ed book
Dreamweaver CS3 with CSS,Ajax and php.
>From one of the chapters I have created a feedback form which worked
correctly sending the mail to me, the next chapter goes on to create
an input form where users can leave comments on the website this part
of it also works correctly. I am trying to merge the 2 in order to be
sent an email when the user posts a comment on the website but it
comes up with the following errors:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
result resource in ...
Warning: mysql_free_result(): supplied argument is not a valid MySQL
result resource in ...
My code is as follows:
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (array_key_exists('submitcomments', $_POST)) {
//mail processing script
$to = '[EMAIL PROTECTED]';
$subject = 'Quick Contact Form';
// list expected fields
$expected = array('hidden', 'nick', 'comment');
// set required fields
$required = array('hidden', 'nick' , 'comment');
$process = '../includes/mailprocess.inc.php';
if (file_exists($process) && is_readable($process)) {
include ($process);
}
else {
$mailSent = false;
mail ($to , 'Server problem ', "$process can't be read" ); }
if($mailSent) {
require_once('../Connections/conComments.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;
}
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"]
== "commentsform")) {
$insertSQL = sprintf("INSERT INTO comments (nick, comments, hidden)
VALUES (%s, %s, %s)",
GetSQLValueString($_POST['nick'], "text"),
GetSQLValueString($_POST['comments'], "text"),
GetSQLValueString($_POST['hidden'], "text"));
mysql_select_db($database_conComments, $conComments);
$Result1 = mysql_query($insertSQL, $conComments) or die(mysql_error
());
}
$maxRows_commentsQuery = 10;
$pageNum_commentsQuery = 0;
if (isset($_GET['pageNum_commentsQuery'])) {
$pageNum_commentsQuery = $_GET['pageNum_commentsQuery'];
}
$startRow_commentsQuery = $pageNum_commentsQuery *
$maxRows_commentsQuery;
mysql_select_db($database_conComments, $conComments);
$query_commentsQuery = "SELECT * FROM comments WHERE hidden
= 'irfaninstall' ORDER BY submitted DESC";
$query_limit_commentsQuery = sprintf("%s LIMIT %d, %d",
$query_commentsQuery, $startRow_commentsQuery,
$maxRows_commentsQuery);
$commentsQuery = mysql_query($query_limit_commentsQuery,
$conComments) or die(mysql_error());
$row_commentsQuery = mysql_fetch_assoc($commentsQuery);
if (isset($_GET['totalRows_commentsQuery'])) {
$totalRows_commentsQuery = $_GET['totalRows_commentsQuery'];
} else {
$all_commentsQuery = mysql_query($query_commentsQuery);
$totalRows_commentsQuery = mysql_num_rows($all_commentsQuery);
}
$totalPages_commentsQuery = ceil($totalRows_commentsQuery/
$maxRows_commentsQuery)-1;
}}
?>
my form is as follows:
<p class="lastP">The installation is now complete. Clicking on
the 'Done' Button will launch the Irfanview FAQ.</p>
<h1>Did you find this tutorial helpful? Please leave a
comment....</h1>
<form name="commentsform" action="<?php echo $editFormAction; ?>"
method="POST">
<input type="hidden" name="hidden" value="irfaninstall" />
<p><label for="name">Name:<?php if (isset($missing) && in_array
('nick', $missing)) { ?>
<span class="warning">*</span><?php } ?><br/></label>
<input type="text" name="nick" id="nick" <?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['nick']).'"';
} ?>/>
</p>
<p>
<label for="comments">Comments:<?php if (isset($missing) && in_array
('comments', $missing)) { ?>
<span class="warning">*</span><?php } ?></label>
<br />
<textarea name="comments" id="comments" cols="45" rows="5"><?php if
(isset($missing)) {
echo htmlentities($_POST['comments']);
} ?></textarea>
</p>
<p>
<label for="submit"></label>
<input type="submit" name="submitcomments" id="submit"
value="Submit" />
</p>
<input type="hidden" name="MM_insert" value="commentsform" />
</form>
<?php do { ?>
<div class="comments">
<p><?php echo $row_commentsQuery['comments']; ?></p>
<p><?php echo $row_commentsQuery['nick']; ?> <?php echo
$row_commentsQuery['submitted']; ?></p>
</div>
<?php } while ($row_commentsQuery = mysql_fetch_assoc
($commentsQuery)); ?>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
<p class="warning">Please complete the missing item(s) indicated.</p>
<?php
}
elseif ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message.
Please try later.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p class="thanks">Your message has been sent. Thank you for your
feedback.
</p>
<?php } ?>
</div>
</body>
</html>
<?php
mysql_free_result($commentsQuery);
?>
I appreciate any help at all!
Regards,
Clare Green.