-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_in_php.php
More file actions
102 lines (89 loc) · 3.5 KB
/
Copy pathcsv_in_php.php
File metadata and controls
102 lines (89 loc) · 3.5 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV functions in php</title>
</head>
<body>
<form method="POST">
<strong>Enter question:</strong>
<input type="text" name="que" size="120"><br><br>
<label><strong> Option A:</strong></label><input type="text" name="o1" size="50">
<label><strong> Option B:</strong></label><input type="text" name="o2" size="50"><br><br>
<label><strong> Option C:</strong></label><input type="text" name="o3" size="50">
<label><strong> Option D:</strong></label><input type="text" name="o4" size="50"><br><br>
<input type="reset" value="clear">
<input type="submit" value="submit" name="sub"><br><br>
</form>
<?php
//php for appemding questions
if(isset($_POST['sub']))
{
// below code for creating or opening csv file
$myfile=fopen("quest_bank.csv","a") or die("ERROR! Unable to open file");
//below code for first line
//$inputdata=["Questions","Option A","Option B","Option C","Option D"];
$inputdata=[$_POST['que'],$_POST['o1'],$_POST['o2'],$_POST['o3'],$_POST['o4']];
$append=fputcsv($myfile,$inputdata);
if($append===true)
{
echo"Data written in file successfull.";
}
fclose($myfile);
}
?>
<form method="POST">
<input type="submit" value="retrive data" name="ret">
</form>
<?php
//php for retriving data
if(isset($_POST['ret']))
{
// below code for creating or opening csv file
// $myfile=fopen("quest_bank.csv","w") or die("ERROR! Unable to open file");
$myfile=fopen("quest_bank.csv","r") or die("ERROR! Unable to open file");
//below code for first line
//$inputdata=["Questions","Option A","Option B","Option C","Option D"];
//$inputdata=[$_POST['que'],$_POST['o1'],$_POST['o2'],$_POST['o3'],$_POST['o4']];
echo "<form method='POST'>";
echo "<table border='1' cellspacing='0' style='text-align:center;'>";
$rowcount=0;
while(($check=fgetcsv($myfile))!==false)
{ echo "<tr>";
$columncount=0;
foreach ($check as $line)
{
if($rowcount!==0 )
{
if($columncount!==0)
{
echo "<td>"."<input type='radio' ".$columncount." name=".$rowcount." required >";
echo $line;
echo "</td>";
}
else
{
echo "<td>".$line."</td>";
}
}
$columncount++;
}
echo "</tr>";
$rowcount++;
}
echo "</table>";
echo "<br>"."<input type='submit' value='submit your answers' name='suball'>";
echo "</form>";
fclose($myfile);
}
?>
<?php
if(isset($_POST['suball']))
{
print_r($_POST);
}
?>
</body>
</html>