Hi,

I am using a form that inserts 5 rows simultaneously into a table of MySQL DB, sometimes there are values for only 2 - 3 rows, but the empty form fields results insertion of "0" in other rows.

Plz tell me how to avoid insertion of the row that has no value in any of the fields., thanks.

Rahul.

    You could test all fields for a null value...

    if(!$formField) {
    echo "Its a NULL, 0, or FALSE";
    } elseif($formField) {
    echo "Its fine, we can put it in the db.";
    }

      Can you plz tell me how to put that condition in the following code, thanks.

      <?php
      require_once("dbconn.php");
      $scheme = $_POST['scheme'];
      $date = date('d m, Y');
      
      $pro1 = $_POST['pro1'];
      $mindep1 = $_POST['mindep1'];
      $maxdep1 = $_POST['maxdep1'];
      $mat1 = $_POST['mat1'];
      $rate1 = $_POST['rate1'];
      
      $pro2 = $_POST['pro2'];
      $mindep2 = $_POST['mindep2'];
      $maxdep2 = $_POST['maxdep2'];
      $mat2 = $_POST['mat2'];
      $rate2 = $_POST['rate2'];
      
      $pro3 = $_POST['pro3'];
      $mindep3 = $_POST['mindep3'];
      $maxdep3 = $_POST['maxdep3'];
      $mat3 = $_POST['mat3'];
      $rate3 = $_POST['rate3'];
      
      $pro4 = $_POST['pro4'];
      $mindep4 = $_POST['mindep4'];
      $maxdep4 = $_POST['maxdep4'];
      $mat4 = $_POST['mat4'];
      $rate4 = $_POST['rate4'];
      
      $pro5 = $_POST['pro5'];
      $mindep5 = $_POST['mindep5'];
      $maxdep5 = $_POST['maxdep5'];
      $mat5 = $_POST['mat5'];
      $rate5 = $_POST['rate5'];
      
      $query="INSERT INTO sch_details(schid, date) values('$scheme', '$date')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      
      $query="INSERT INTO sch_details(schid, propay, mindeposit, maxdeposit, maturity, rate) values('$scheme', '$pro1', '$mindep1', '$maxdep1', '$mat1', '$rate1')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      $query="INSERT INTO sch_details(schid, propay, mindeposit, maxdeposit, maturity, rate) values('$scheme', '$pro2', '$mindep2', '$maxdep2', '$mat2', '$rate2')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      $query="INSERT INTO sch_details(schid, propay, mindeposit, maxdeposit, maturity, rate) values('$scheme', '$pro3', '$mindep3', '$maxdep3', '$mat3', '$rate3')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      $query="INSERT INTO sch_details(schid, propay, mindeposit, maxdeposit, maturity, rate) values('$scheme', '$pro4', '$mindep4', '$maxdep4', '$mat4', '$rate4')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      $query="INSERT INTO sch_details(schid, propay, mindeposit, maxdeposit, maturity, rate) values('$scheme', '$pro5', '$mindep5', '$maxdep5', '$mat5', '$rate5')";
      if(!mysql_query($query, $link))
      	{
      	$dberror=mysql_error();
      	return false;
      	}
      ?>
      

        um, Not going to do everything for you.. but here is one..

        
        $scheme = $_POST['scheme'];
        
        if(!$scheme) {
        echo "Scheme is empty, or not true.<br>";
        } elseif($scheme) {
        echo "Scheme is not empty as well as true.<Br>";
        }
        
        

        Thats pretty understandable right? But there is easier ways, just not going to go all out...

          You might find this usefull

          if (IsSet($_POST['scheme']) && $_POST['scheme'] != "") $scheme = $_POST['scheme'];
          else $scheme = "";
          if (IsSet($_POST['pro1']) && $_POST['pro1'] != "") $pro1 = $_POST['pro1'];
          else $scheme = "";
          
          //Check if for all vars.
          
          //Then check in there's no value for one of them
          
          if ($action == "insert") {
          
          // here you must enter all vars that are required
              if ($scheme == "" || $pro1 == "") {
             echo "enter all fields...";
             }
             else {
             echo "ready to insert
             // insert them here
             }
          
          }
          else {
          // show the form
          }
          
            Write a Reply...