Jump to content

Automatically not accept empty entries or delete empty entries on table


xerox02

Recommended Posts

$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);
  }
  

Link to comment
Share on other sites

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);
  }
  }
  

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.';
  } 
  }
  
  

Link to comment
Share on other sites

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);
  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.