chronister Posted March 4, 2007 Share Posted March 4, 2007 Hi all, I am creating an interface for my wife to keep track of what cross stitch threads she has. I have created a text area so she can enter a bunch at a time. I am trying to get the script to skip over blank lines. The code for this piece is here: <?php if($_POST['add_floss']){ // submit button has been pressed $num=nl2br($_POST['floss_num']); // grab the textarea data, run through new line 2 break $name=nl2br($_POST['floss_name']);// grab the textarea data, run through new line 2 break $floss_num=explode('<br />',$num); // explode on the <br>, create array $floss_name=explode('<br />',$name); // explode on the <br>, create array connectdb(); // call to connectdb function foreach($floss_num as $v){ if(isset($v)){ // if $v is not empty run query and insert $query="INSERT INTO floss (floss_num , floss_qty , floss_name ) VALUES ('$v', '1', NULL)"; $result=mysql_query($query); }//end if $v }//end foreach foreach($floss_name as $v){ if(isset($v)){ // if $v is not empty run query and insert $query="INSERT INTO floss (floss_num , floss_qty , floss_name ) VALUES (NULL, '1', '$v')"; $result=mysql_query($query); }//end if $v };// end foreach } // end if $_POST[]; ?> I have tried isset(), if(strlen($v) > 0) if($v!=="") & if($v!==" ") and no matter what it inserts 1 blank entry. I type something like this in the textarea ------- 123 456 789 65477 ------- It will skip all empty items but 1 every time Anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/41162-solved-inserting-empty-data-into-mysql-when-not-supposed-to/ Share on other sites More sharing options...
pocobueno1388 Posted March 4, 2007 Share Posted March 4, 2007 Insted of if($v!=="") Try: if($v != "") Link to comment https://forums.phpfreaks.com/topic/41162-solved-inserting-empty-data-into-mysql-when-not-supposed-to/#findComment-199378 Share on other sites More sharing options...
chronister Posted March 4, 2007 Author Share Posted March 4, 2007 Thanks Paco... But same results sir. I got it though, I did this foreach($floss_num as $v){ $v=trim($v); //white space was being added for some reason if(strlen($v) > 0){ seems that an empty whitespace was the culprit Link to comment https://forums.phpfreaks.com/topic/41162-solved-inserting-empty-data-into-mysql-when-not-supposed-to/#findComment-199411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.