deepson2 Posted June 19, 2009 Share Posted June 19, 2009 Hello, I want to do csv file validation, like i dont want insert blank field. and others validations as well. but now, the status is with blank field also data is getting inserted. i have tried a lot. can anyone have look and please tell me how can i prevent my database from blank fields here is my code if(isset($_POST['Submit'])=="Upload") { $handle = fopen("c:../../files/abbr_details.csv","r"); while ($data = fgetcsv ($handle, 1000, ",")) { if ((empty($abbreviation)) or (empty($full_name)) or (empty($significance)) or (empty($used))){ echo "You forgot to enter your some one of the value, please go back and try again"; exit(); } else{ $query = mysql_query("SELECT * FROM abbr_details WHERE (full_name='$full_name' AND abbreviation='$abbreviation' AND significance='$significance' AND used='$used')") or die(mysql_error()); if(mysql_num_rows($query) >= 1) { } else { $query1 = "INSERT INTO abbr_details (abbreviation,full_name,significance ,used) values ('".$abbreviation."','".$full_name."','".$significance ."','".$used."')"; $result1 = mysql_query($query1) or die('Query failed: ' . mysql_error()); if(mysql_affected_rows() > 0) { echo "inserted"; } else { echo "not inserted"; } } }} fclose ($handle); mysql_free_result($query); } ?> please help me. thanks in advance. Link to comment https://forums.phpfreaks.com/topic/162895-csv-file-validation/ Share on other sites More sharing options...
priti Posted June 19, 2009 Share Posted June 19, 2009 what $abbreviation is showing ??? I amazed that you are not fetching data from $data array and you are not using this array to fetch the data. Can you print what is the output of print_r($data)??? Refer :http://in2.php.net/manual/en/function.fgetcsv.php for more details Link to comment https://forums.phpfreaks.com/topic/162895-csv-file-validation/#findComment-859511 Share on other sites More sharing options...
deepson2 Posted June 19, 2009 Author Share Posted June 19, 2009 I am so sorry priti. here is my proper code. and insertion is pretty much happening. the thing is only validation. please help me. if(isset($_POST['Submit'])=="Upload") { $handle = fopen("c:/abbr_details.csv","r"); while ($data = fgetcsv ($handle, 1000, ",")) { $abbreviation = $data[0]; $full_name = $data[1]; $significance = $data[2]; $used = $data[3]; $query = mysql_query("SELECT * FROM abbr_details WHERE (full_name='$full_name' AND abbreviation='$abbreviation' AND significance='$significance' AND used='$used')") or die(mysql_error()); if(mysql_num_rows($query) >= 1) { } else { $query1 = "INSERT INTO abbr_details (abbreviation,full_name,significance ,used) values ('".$abbreviation."','".$full_name."','".$significance ."','".$used."')"; $result1 = mysql_query($query1) or die('Query failed: ' . mysql_error()); if(mysql_affected_rows() > 0) { echo "inserted"; } else { echo "not inserted"; } } } fclose ($handle); mysql_free_result($query); } ?> Link to comment https://forums.phpfreaks.com/topic/162895-csv-file-validation/#findComment-859513 Share on other sites More sharing options...
deepson2 Posted June 20, 2009 Author Share Posted June 20, 2009 Any help??? Link to comment https://forums.phpfreaks.com/topic/162895-csv-file-validation/#findComment-860024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.