I have just recently finished a review type site for paintball products:
http://www.pbreview.com
Some people have emailed me about getting erros when they submit a review. This is the file that stores the review to the database and I can't figure out why it gives an error sometimes but no other times:
<?php
require("global.php3") ;
require("top.html");
if (ereg(".+@.+\..+$", $usremail1)) {
if (!$usrname1 || !$usremail1 || !$good1 || !$bad1 || !$summary1) {
printf("You did not fill in all of the fields!<br><br>Please go back and fix it!") ;
require("bottom.html");
exit() ;
}
$date = date("m/d/y");
$usrname2 = stripslashes(htmlspecialchars($usrname1));
$usremail2 = stripslashes(htmlspecialchars($usremail1));
$good2 = stripslashes(htmlspecialchars($good1));
$bad2 = stripslashes(htmlspecialchars($bad1));
$summary2 = stripslashes(htmlspecialchars($summary1));
$addStmt = "Insert into REVIEWS(USRNAME, USREMAIL, GOOD, BAD, SUMMARY, RATING, KEYTOPROD, DATE) values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" ;
if (!($link=mysql_pconnect($hostName, $userName, $password))) {
printf("Error") ;
exit() ;
}
if (!mysql_select_db($databaseName, $link)) {
printf("Error") ;
exit() ;
}
if (!mysql_query(sprintf($addStmt, $usrname2, $usremail2, $good2, $bad2, $summary2, $rating1, $id, $date), $link)) {
sprintf("Error in executing %s stmt", $addStmt) ;
sprintf("error:%d %s", mysql_errno($link), mysql_error($link)) ;
require("bottom.html");
exit() ;
}
printf("Review Added!<br><br><a href=\"view.php3?id=" . $id . "\">Back to Product</a>");
require("bottom.html");
} else {
printf("Invalid Email Address!<br><br>Please go back and fix it!");
require("bottom.html");
}
?>
Do you see anything wrong with this?
Thanks,
Andrew