hii Very Good Morning
Can anyone tell, how to count INVALID (Numbers) rows in csv file using php… Below code is counting only VALID (Numbers) rows, i want to count. Both Valid & Invalid Rows(Numbers).
plzzzz tell me how to do it ?
<body>
<div style="border:1px dotted #333333; width:300px; margin:0 auto; padding:10px;">
<form name="import" method="post" enctype="multipart/form-data">
<input type="file" name="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include ("connection.php");
if (isset($_POST["submit"])) {
$file = $_FILES['file']['tmp_name'];
$handle = fopen($_FILES['file']['tmp_name'], "r");
$c = 0;
while (($filesop = fgetcsv($handle, 1000, ",")) !== false) {
$contact = $filesop[0];
$message = $filesop[1];
if (preg_match('/(7|8|9)\d{9}/', $contact)) {
$sql = mysql_query("INSERT INTO csv (contact, message) VALUES ('$contact','$message')");
$c = $c + 1;
}
}
if ($sql) {
echo "You database has imported successfully. You have inserted " . $c . " records";
} else {
echo "Sorry! There is some problem.";
}
}
?>
</div>
</body>
Try $total_rows = count($filesop);
and $invalid_rows = $total_rows - $c;
And for goodness sake, get rid of the “mysql_” function while you’re working on the code now so you won’t need to do it later. At least swap it out to “mysqli_”
I’m not sure what you mean. Do you mean that you want to leave the form in place on the screen, have the file uploaded in the background and then display the results on the original page? If so, you’ll need to look at Ajax to handle the upload, but I can’t see where you will display the data on your form page, or even how it will be logical to the user to still have the form displayed after they have uploaded the file.
When i click on submit button output must display in same page only. It displaying in other page…
Our sir told ur using POST & ACTION, so it displaying in other page…
So he told to try in Javascript…