Hi there I am a beginner of PHP, I am attempting to design a website using PHP and PHPMyAdmin. This dashboard is supposed to show sales of graphs.
Error Example:Notice: Undefined variable: jan in C:\xampp\htdocs\FYP2\admin\dashboard.php on line 459 the same applies to as mentioned previously, lines 460, 461, 462... 470
I have included the line numbers next to the lines of code with the errors (e.g.Line 460)
What is causing these problems and what do I need to do to resolve them ???
What I have tried:
1 <?php
2
3 include("includes/db.php");
4
5 $query = "select * from sales_chart";
6 $result = mysqli_query($con,$query);
7
8 if(mysqli_num_rows($result) >1){
9 while($row = mysqli_fetch_assoc($result)){
10
11 $jan = $_row['jan'];
12 $feb = $_row['feb'];
13 $march = $_row['march'];
14 $april = $_row['april'];
15 $may = $_row['may'];
16 $june = $_row['june'];
17 $july = $_row['july'];
18 $august = $_row['august'];
19 $sept = $_row['sept'];
20 $oct = $_row['oct'];
21 $nov = $_row['nov'];
22 $dec = $_row['dec'];
23
24 }
25 }
26 else
27 {
28 echo "something went wrong";
29 }
30
31
32
33 ?>
34 <html>
35 <head>
36
37 <link href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.css" rel= "stylesheet">
38 <link href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.css" rel= "stylesheet">
39
40
41 </head>
42 <body>
43
44 <canvas id="myChart" style="height:auto; width: 500px;"></canvas>
45
46
47 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.js"></script>
48 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
49 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.js"></script>
50 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
51
52 <?php
53
54 echo "<input type='hidden' name='jan' id='jan' value = '$jan'>";
55 echo "";
56 echo "";
57 echo "";
58 echo "";
59 echo "";
60 echo "";
61 echo "";
62 echo "";
63 echo "";
64 echo "";
65 echo "";
66 ?>
67
68
69
70
71
72 var jan = document.getElementById("jan").value;
73 var feb = document.getElementById("feb").value;
74 var march = document.getElementById("march").value;
75 var april = document.getElementById("april").value;
76 var may = document.getElementById("may").value;
77 var june = document.getElementById("june").value;
78 var july = document.getElementById("july").value;
79 var august = document.getElementById("august").value;
80 var sept = document.getElementById("sept").value;
81 var oct = document.getElementById("oct").value;
82 var nov = document.getElementById("nov").value;
83 var dec = document.getElementById("dec").value;
84
85 window.onload = function()
86 {
87 var randomScalingFactor = function(){
88 return Math.round(Math.random() *100);
89 };
90
91 var config = {
92 type: 'bar',
93 datasets: [{
94 data: [
95 jan,
96 feb,
97 march,
98 april,
99 may,
100 june,
101 july,
102 august,
103 sept,
104 oct,
105 nov,
106 dec
107 ],
108 borderColor: "#fff",
109 borderWidth: "3",
110 hoverBorderColor: "#000"
111
112 label: 'Monthly Sales Report',
113
114 backgroundColor:[
115
116 pink,
117 blue,
118 navyblue,
119 cyan,
120 red,
121 green,
122 dark green,
123 yellow,
124 purple,
125 lime,
126 magenta,
127 skyblue
128
129 ],
130
131 hoverBackgroundColor: [
132
133 black,
134 black,
135 black,
136 black,
137 black,
138 black,
139 black,
140 black,
141 black,
142 black,
143 black,
144 black
145
146 ],
147
148 }],
149
150 Labels: [
151
152 'jan',
153 'feb',
154 'march',
155 'april',
156 'may',
157 'june',
158 'july',
159 'august',
160 'sept',
161 'oct',
162 'nov',
163 'dec'
164 ]
165 },
166
167 options: {
168 responsive: true;
169
170 }
171 };
172
173 var ctx = document.getElementById('myChart').getContext('2d');
174 window.myPie = new Chart(ctx, config);
175
176 };