xerox02 Posted July 22, 2010 Share Posted July 22, 2010 For some reason on my excuse submit ( http://excusesexcuses.net/submit1.php ) , I get a lot of empty rows in my mysql table. Is there a way I can automatically not accept empty entries or delete empty entries on table? Thanks a lot, Xerox02 Quote Link to comment Share on other sites More sharing options...
Alex Posted July 22, 2010 Share Posted July 22, 2010 You can validate your input with a function like empty and not submit it to the database if it is empty. For more specific help we'll need to see relevant code. Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_database", $con); require_once('recaptchalib.php'); $privatekey = "private_key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."); } else { $sql="INSERT INTO pendingquotes (quotes, email, name) VALUES ('$_POST[quotes]','$_POST[email]','$_POST[name]')"; mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } Quote Link to comment Share on other sites More sharing options...
Alex Posted July 22, 2010 Share Posted July 22, 2010 Your code could look something like: $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_database", $con); require_once('recaptchalib.php'); $privatekey = "private_key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."); } else { if(empty($_POST['quotes'])) { // Tell them they missed a required field } else { $sql="INSERT INTO pendingquotes (quotes, email, name) VALUES ('$_POST[quotes]','$_POST[email]','$_POST[name]')"; mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } } Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 Your code could look something like: $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_database", $con); require_once('recaptchalib.php'); $privatekey = "private_key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."); } else { if(empty($_POST['quotes'])) { // Tell them they missed a required field } else { $sql="INSERT INTO pendingquotes (quotes, email, name) VALUES ('$_POST[quotes]','$_POST[email]','$_POST[name]')"; mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } } Thanks a lot man, I can have it modify each field too. Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 For some reason, this doesn't seem to know when it's empty Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 I would think this would work, but it doesn't $sql="INSERT INTO pendingquotes (quotes, email, name) VALUES ('$_POST[quotes]','$_POST[email]','$_POST[name]')"; if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."); } else { if(empty($_POST['quotes'])) { // Tell them they missed a required field echo 'missed'; } if (isset(($_POST['quotes'])) { mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } } It gives me this error. Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '$' in /home/a1451858/public_html/submission.php on line 114 It shouldn't tho because the t_variable is definied at $sql. Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 I tried this, but the problem is that when it's not empty it doesn't submit to database $sql="INSERT INTO pendingquotes (quotes, email, name) VALUES ('$_POST[quotes]','$_POST[email]','$_POST[name]')"; $_POST[quotes] = $quote; if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."); } else { if (isset($quote)) { mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } else if(empty($quote)) { // Tell them they missed a required field echo 'You did not write a quote.'; } } Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 22, 2010 Share Posted July 22, 2010 going back to your previous post: { if(empty($_POST['quotes'])) { // Tell them they missed a required field echo 'missed'; } if (isset(($_POST['quotes'])) { // THERE IS AN EXTRA PARENTHESIS HERE mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } you have a syntax error in the IF (ISSET( statement. but you do not want to use ISSET there. A variable can be SET and still be EMPTY. You should probably just use an ELSE (off of the IF (EMPTY( above it ) { if(empty($_POST['quotes'])) { // Tell them they missed a required field echo 'missed'; } else { mysql_query($sql,$con); echo 'Thanks for your submission '; mysql_close($con); } Quote Link to comment Share on other sites More sharing options...
xerox02 Posted July 22, 2010 Author Share Posted July 22, 2010 Thanks man, you know what happened was, my html document had an extra 2 spaces in the text area for no reason. So it never looked empty for some reason. Thanks a lot you guys. This forum has taught me soo much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.