I've got a form that displays correctly, etc., yet when it comes time to submit, I receive the following errors:
An error occurred in script /home/virtual/site4/fst/var/www/files/config.inc on line 7: Undefined index: did
An error occurred in script /home/virtual/site4/fst/var/www/files/config.inc on line 7: Undefined index: dname
An error occurred in script /home/virtual/site4/fst/var/www/files/config.inc on line 7: Undefined index: qset1
An error occurred in script /home/virtual/site4/fst/var/www/files/config.inc on line 7: Use of undefined constant HTTP_X_FORWARDED_FOR - assumed 'HTTP_X_FORWARDED_FOR'
Additionally, in the script, I ask that if the comments area is blank, to display the error message, "You have not entered any comments". This is another message I'm receiving, despite the fact that comments were entered.
Below, I'm posting three parts of the code. The first is my config.inc script, the second is the code from the form, and the last part is the form itself. Help is ENORMOUSLY appreciated.
Thanks....
CONFIG.INC
<?php
error_reporting (E_ALL);
function my_error_handler ($e_number, $e_message) {
$message = 'An error occurred in script ' . __FILE__ . '
on line ' . __LINE__ . ": $e_message";
//error_log ($message, 1, 'admin@vocalize.biz');
// Production (send email)
echo '<font color="red" size="+1">', $message, '</font>';
}
set_error_handler('my_error_handler');
?>
PHP CODE FROM FORM
<?php
require_once ('../files/config.inc');
$did=($_GET['did']);
$dname=($_GET['dname']);
$q1=($_POST['qset1']);
$q2=($_POST['qset2']);
$q3=($_POST['qset3']);
$q4=($_POST['qset4']);
$q5=($_POST['qset5']);
$q6=($_POST['qset6']);
$q7=($_POST['qset7']);
$q8=($_POST['qset8']);
$q9=($_POST['qset9']);
$q10=($_POST['qset10']);
$q11=($_POST['qset11']);
if (isset($_POST['submit'])) {
require_once ('../mysql_connect.php');
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{ 2,4} $",
stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid email address</font></p>';
}
if (eregi ("^[[:alnum:]_]{ 4,20} $", stripslashes(trim($_POST['username'])))) {
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid username</font></p>';
}
if (eregi ("^[[:alnum:]_]{ 4,2000} $", stripslashes(trim($_POST['comments'])))) {
$cm = escape_data($_POST['comments']);
} else {
$cm = FALSE;
echo '<p><font color="red" size="+1">You have not entered any comments</font></p>';
}
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ip = getenv('HTTP_X_FORWARD_FOR');
$h = gethostbyaddr($ip);
} else {
$ip = getenv('REMOTE_ADDR');
$h = gethostbyaddr($ip);
}
if ($e && $u && $cm && $ip && $h) {
$query = "SELECT username FROM tablename WHERE username='$u'";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 0) {
$query = "INSERT INTO ratings (doc_id, username, email, host, ipaddress, comments, qset1, qset2, qset3, qset4,
qset5, qset6, qset7, qset8, qset9, qset10, qset11, revdate) VALUES ('$did', '$u', '$e', '$h', '$ip',
'$cm', '$q1', '$q2', '$q3', '$q4', '$q5', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', NOW())";
$result = @mysql_query ($query);
if ($result) {
$body = "Thank you for '{ $_GET['dname']} '. ";
mail ($_POST['email'], 'Thanks',$body, 'From: [email]admin@12345.com[/email]');
echo '<p> thanks</p>';
} else {
echo '<p>Please go back and try again.</p>';
}
} else {
echo '<p><font color="red">error.</font></p>';
}
} else {
echo '<p>Please go back and try again.</p>';
}
mysql_close();
}
?>
FORM
<p>This is for: <strong> <?php echo ($_GET['dname']);?></strong></p>
<table>
<tr><td valign="top">
<form name="thisform1" id="thisform1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>Please enter your email address:
<input name="email" type="text" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
<p>Please select a username:
<input name="username" type="text" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"/>
<P>Comments<br />
<textarea name="comments" cols="55" rows="10" value="<?php if (isset($_POST['comments'])) echo $_POST['comments']; ?>"></textarea>
</td></tr>
<tr><td>
<strong>(Optional Section) Please rate the following 11 areas:</strong>
<P><strong>Area1</strong><br />
<label><input type="radio" name="qset1" value="5" />5</label><br />
<label><input type="radio" name="qset1" value="5" />4</label><br />
<label><input type="radio" name="qset1" value="5" />3</label><br />
<label><input type="radio" name="qset1" value="5" />2</label><br />
<label><input type="radio" name="qset1" value="5" />1</label><br />
<P><input name="submit" type="submit" value="Submit"/>
</tr>
</table>
</td>
</tr>
</form>