june_c21 Posted March 30, 2010 Share Posted March 30, 2010 Hi , I got a question . How to stop enter the data into database when the $causes == NULL ? Here is my code <?php include './includes/header.php'; for ($i=1;$i<11;$i++) { $id = $_GET ['id']; $causes = $_POST ['causes'][$i]; $corrective_action = $_POST ['corrective_action'][$i]; $name = $_POST ['name'][$i]; $date = $_POST ['date'][$i]; $completedate = $_POST ['completedate'][$i]; $remarks = $_POST ['remarks'][$i]; $status = $_POST ['status']; $query= "INSERT INTO corrective_action( id, causes, corrective_action, name, date, completedate, remarks ) VALUES ('$id','$causes','$corrective_action','$name','$date','$completedate','$remarks') "; $result = mysql_query($query,$dblink); } $query1= "UPDATE event SET status= '$status' where id=$id "; $result1 = mysql_query($query1,$dblink); ?> Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 30, 2010 Share Posted March 30, 2010 if(is_null($causes)) break; Or, if you want the loop to continue even if $causes is null, use this: if(is_null($causes)) continue; Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 30, 2010 Author Share Posted March 30, 2010 TQVM 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.