-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertWebsite.php
executable file
·67 lines (49 loc) · 1.62 KB
/
InsertWebsite.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<body>
<form action = "./InsertWebsite.php" method ="post">
<input type = "submit" name = "submit" value = "Insert All">
</form>
<?php
require 'connect.php';
if(isset($_POST['submit']) && !empty($_POST['submit']))
{
$fp = fopen("DistrictWebsite.txt","r");
$j=0;
while(!feof($fp))
{
$line= fgets($fp);
$pos=my_ofset($line);
$len=strlen($line)-1;
$Code = substr($line, 0, 2);
$line2 = substr($line, 2);
$details[0] = strtok($line2, "\t");
$details[0] = trim($details[0]);
$Name = $details[0];
$i=0;
while ($details[$i] !== false)
{
$details[++$i] = strtok("\t");
}
$Website = $details[5];
$Name= trim($Name);
$Code= trim($Code);
$Website= trim($Website);
echo ++$j."\t".$Code."\t".$Name."\t".$Website."<br>";
$query = "INSERT INTO WebsiteDistricts VALUES('$Code', '$Name','$Website','Punjab' )";
if($conn->query($query))
{
echo "Data inserted.<br>";
}
else
{
echo "Error during inserting data.\n";
}
}
}
function my_ofset($text){
preg_match('/^\D*(?=\d)/', $text, $m);
return isset($m[0]) ? strlen($m[0]) : false;
}
?>
</body>
</html>