php variable
ik had dit ook via section geprobeerd, wat ik op zich mooier vind maar dan ook krijg ik de waarde niet mee.
kan iemand mij eventueel aangeven waar ik mis ga.
Code (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
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
103
104
105
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
103
104
105
<?
session_start();
include_once 'css/inf.php';
$kmstand = null;
$startstop = 'start';
$tellingB = null;
$_SESSION['kmstandvorige'] = $kmstand;
$_SESSION['first'] = true;
// $_SESSION['tellingB2'] = $tellingB;
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {
printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = 'SELECT * FROM `kmstand` getLastRecord ORDER BY id DESC LIMIT 1';
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$i = 0;
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$id = $row['id'];
$kmstand = $row['kmstand'];
$startstop = $row['startstop'];
}
}
$action = "kmstand2.php?tellingB=".$tellingB;
?>
</head>
<body>
<div style="text-align:center;padding:10px;margin-top:7px;font-size:12px;">
<form action="<? echo $action ?>" method="post" enctype="multipart/form-data" class="center13" id="postform">
<p> </p>
<p><span class="textbox">Kmstand<br>
</span>
<input class="MyB5" name="kmstand" type="text" id="kmstand" size="15" />
</p>
<p><span class="font16">Vorige km stand<br>
<? echo $kmstand ?></span><br>
<br>
<input name="startstop" type="text" class="MyB5" id="startstop" value="<?echo $startstop ?>" size="15" readonly />
<br>
<table width="200" border="0" align="center">
<tr>
<td><input name="tellingB" id="tellingB" type="radio" value="Proefrit" ></td>
<td><span class="font16">Proefrit</span></td>
</tr>
</table>
<br>
<br>
<p>
<input type="submit" class="MyB1" value="Toevoegen" onClick="this.disabled=true;this.value='Bezig 1 Moment...';this.form.submit();" />
</p><br>
<br>
</form>
<button id="myButton3" class="MyB3" >Tanken</button>
<br>
<br>
<button id="myButton5" class="MyB5" >Overzicht / Mail</button>
<br />
</div>
<script type="text/javascript">
document.getElementById("myButton3").onclick = function () {
location.href = "tanken.php";
};
document.getElementById("myButton5").onclick = function () {
location.href = "email-kmstanden.php";
};
</script>
session_start();
include_once 'css/inf.php';
$kmstand = null;
$startstop = 'start';
$tellingB = null;
$_SESSION['kmstandvorige'] = $kmstand;
$_SESSION['first'] = true;
// $_SESSION['tellingB2'] = $tellingB;
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {
printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = 'SELECT * FROM `kmstand` getLastRecord ORDER BY id DESC LIMIT 1';
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$i = 0;
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$id = $row['id'];
$kmstand = $row['kmstand'];
$startstop = $row['startstop'];
}
}
$action = "kmstand2.php?tellingB=".$tellingB;
?>
</head>
<body>
<div style="text-align:center;padding:10px;margin-top:7px;font-size:12px;">
<form action="<? echo $action ?>" method="post" enctype="multipart/form-data" class="center13" id="postform">
<p> </p>
<p><span class="textbox">Kmstand<br>
</span>
<input class="MyB5" name="kmstand" type="text" id="kmstand" size="15" />
</p>
<p><span class="font16">Vorige km stand<br>
<? echo $kmstand ?></span><br>
<br>
<input name="startstop" type="text" class="MyB5" id="startstop" value="<?echo $startstop ?>" size="15" readonly />
<br>
<table width="200" border="0" align="center">
<tr>
<td><input name="tellingB" id="tellingB" type="radio" value="Proefrit" ></td>
<td><span class="font16">Proefrit</span></td>
</tr>
</table>
<br>
<br>
<p>
<input type="submit" class="MyB1" value="Toevoegen" onClick="this.disabled=true;this.value='Bezig 1 Moment...';this.form.submit();" />
</p><br>
<br>
</form>
<button id="myButton3" class="MyB3" >Tanken</button>
<br>
<br>
<button id="myButton5" class="MyB5" >Overzicht / Mail</button>
<br />
</div>
<script type="text/javascript">
document.getElementById("myButton3").onclick = function () {
location.href = "tanken.php";
};
document.getElementById("myButton5").onclick = function () {
location.href = "email-kmstanden.php";
};
</script>
code pagina 2 maar die vind ik niet belangrijk, wil eerste de waarde meegenomen hebben
als ik deze op mijn de php heb, fix ik daar de rest wel weer.
Code (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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<head>
<title>kmstand</title>
<link rel="stylesheet" href="css/style_fdeel.css">
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
</script>
</p>
<p>
<?
session_start();
include_once 'css/inf.php';
echo $tellingB;
// echo $_SESSION['first'] ;
if ( $_SESSION['first'] == true ) {
$_SESSION['first'] = false;
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {
printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = 'SELECT * FROM `kosten` getLastRecord ORDER BY id DESC LIMIT 1';
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$i = 0;
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$literprijs = $row['literprijs'];
}
}
$kmstand = $_POST['kmstand'];
$startstop = $_POST['startstop'];
//$datum = date("Y/m/d");
$datum = date("j-n-Y");
$tijd = date("H:i");
$telling = '0';
$kosten = null;
if ( $startstop == 'start' ) {
$startstop = "stop" ; } else {
$startstop = "start" ;
echo '<br>';
$telling = $kmstand - $_SESSION['kmstandvorige'];
echo 'Gereden km '.$telling;
echo '<br>';
echo 'Geschatte kosten rit zijn ';
echo'<br>';
$kosten = number_format( ($literprijs /13 * $telling), 2 );
echo $kosten;
} ;
$con = mysqli_connect($host, $username, $password, $database);
if (mysqli_connect_errno()) {
echo "<BR><BR><BR>Connect failed: ", mysqli_connect_error();
};
if ( $_SESSION['tellingB2'] == 'Proefrit' ) {
echo 'Onbetaald';
$tellingB = $telling;
$telling = '0';
};
if ( $_SESSION['tellingB2'] == '' ) {
echo '<br>Betaald';
$tellingB = '0';
};
$sql = "INSERT INTO kmstand VALUES ('','$kmstand','$startstop','$datum','$tijd','$telling','$tellingB')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
$last_id = $con->insert_id;
echo "<BR><BR>Data toegevoegd<BR><BR>";
if ( $startstop == 'start' ) {
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());exit();
}
$query = "SELECT * FROM `usermg` ORDER BY id DESC";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$id = $row['id'];
$user = $row['user'];
$email = $row['email'];
$van = $row['van'];
$to = $email;
$from = $van;
$subject = 'Gereden.';
$bodytext ='<body class="fontwhite"> ';
$bodytext .='<html><p><tr><td></td></tr>';
$bodytext .= '<BR><style type="text/css"> <!-- .center2 { text-align: center; } --> </style>
<body><table width="100%" height="20" border="0" >
<tr>
<td width="105" height="21">kmstand Start :</td>
<td width="700">'.$_SESSION['kmstandvorige'].'</td>
</tr>
<tr>
<td height="21" heigt "25" >kmstand Stop:</td>
<td>'.$kmstand.'</td>
</tr>
<td height="21" heigt "25" >Datum: </td>
<td>'.$datum.'</td>
</tr>
<tr>
<td height="21" heigt "25" >tijd: </td>
<td>'.$tijd.'</td>
</tr>
<tr>
<td height="21" heigt "25" >Gereden km : </td>
<td>'.$telling.'</td>
</tr>
<tr>
<td height="21" heigt "25" >Geschatte kosten : </td>
<td>'.$kosten.'</td>
</tr>
</table>
<table width="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
</body>
</html>';
$userN = $user;
$userE = $email;
$userW = null;
$userM = $bodytext;
$userF = null;
$fromname = $van;
$userS = $subject;
$headers = "From: <".$from."> \r\n";
$headers = "MIME-Version: 1.0";
$headers = "Content-type: text/plain; charset=iso-8859-1";
$userSubject = $subject;
$userEmail = $from;
$headers = "X-Mailer: PHP/".phpversion();
echo '
<div style="text-align:center;padding:10px;margin-top:7px;font-size:25px;">
Email verzonden naar '.$user." - ".$email.' -
</div>';
include($ABSPATH.'config/smtp.php');
echo '<BR>';
}
}
mysqli_close($con);
};
};
?>
<title>kmstand</title>
<link rel="stylesheet" href="css/style_fdeel.css">
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
</script>
</p>
<p>
<?
session_start();
include_once 'css/inf.php';
echo $tellingB;
// echo $_SESSION['first'] ;
if ( $_SESSION['first'] == true ) {
$_SESSION['first'] = false;
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {
printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = 'SELECT * FROM `kosten` getLastRecord ORDER BY id DESC LIMIT 1';
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$i = 0;
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$literprijs = $row['literprijs'];
}
}
$kmstand = $_POST['kmstand'];
$startstop = $_POST['startstop'];
//$datum = date("Y/m/d");
$datum = date("j-n-Y");
$tijd = date("H:i");
$telling = '0';
$kosten = null;
if ( $startstop == 'start' ) {
$startstop = "stop" ; } else {
$startstop = "start" ;
echo '<br>';
$telling = $kmstand - $_SESSION['kmstandvorige'];
echo 'Gereden km '.$telling;
echo '<br>';
echo 'Geschatte kosten rit zijn ';
echo'<br>';
$kosten = number_format( ($literprijs /13 * $telling), 2 );
echo $kosten;
} ;
$con = mysqli_connect($host, $username, $password, $database);
if (mysqli_connect_errno()) {
echo "<BR><BR><BR>Connect failed: ", mysqli_connect_error();
};
if ( $_SESSION['tellingB2'] == 'Proefrit' ) {
echo 'Onbetaald';
$tellingB = $telling;
$telling = '0';
};
if ( $_SESSION['tellingB2'] == '' ) {
echo '<br>Betaald';
$tellingB = '0';
};
$sql = "INSERT INTO kmstand VALUES ('','$kmstand','$startstop','$datum','$tijd','$telling','$tellingB')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
$last_id = $con->insert_id;
echo "<BR><BR>Data toegevoegd<BR><BR>";
if ( $startstop == 'start' ) {
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {printf("<BR><BR><BR>Connect failed: %s\n", mysqli_connect_error());exit();
}
$query = "SELECT * FROM `usermg` ORDER BY id DESC";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$id = $row['id'];
$user = $row['user'];
$email = $row['email'];
$van = $row['van'];
$to = $email;
$from = $van;
$subject = 'Gereden.';
$bodytext ='<body class="fontwhite"> ';
$bodytext .='<html><p><tr><td></td></tr>';
$bodytext .= '<BR><style type="text/css"> <!-- .center2 { text-align: center; } --> </style>
<body><table width="100%" height="20" border="0" >
<tr>
<td width="105" height="21">kmstand Start :</td>
<td width="700">'.$_SESSION['kmstandvorige'].'</td>
</tr>
<tr>
<td height="21" heigt "25" >kmstand Stop:</td>
<td>'.$kmstand.'</td>
</tr>
<td height="21" heigt "25" >Datum: </td>
<td>'.$datum.'</td>
</tr>
<tr>
<td height="21" heigt "25" >tijd: </td>
<td>'.$tijd.'</td>
</tr>
<tr>
<td height="21" heigt "25" >Gereden km : </td>
<td>'.$telling.'</td>
</tr>
<tr>
<td height="21" heigt "25" >Geschatte kosten : </td>
<td>'.$kosten.'</td>
</tr>
</table>
<table width="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
</body>
</html>';
$userN = $user;
$userE = $email;
$userW = null;
$userM = $bodytext;
$userF = null;
$fromname = $van;
$userS = $subject;
$headers = "From: <".$from."> \r\n";
$headers = "MIME-Version: 1.0";
$headers = "Content-type: text/plain; charset=iso-8859-1";
$userSubject = $subject;
$userEmail = $from;
$headers = "X-Mailer: PHP/".phpversion();
echo '
<div style="text-align:center;padding:10px;margin-top:7px;font-size:25px;">
Email verzonden naar '.$user." - ".$email.' -
</div>';
include($ABSPATH.'config/smtp.php');
echo '<BR>';
}
}
mysqli_close($con);
};
};
?>
Gewijzigd op 16/03/2023 22:27:22 door Space gremlin
Ik neem aan dat je bedoelt 'session'?
Pagina 2 regel 23:
echo $tellingB;
Zo haal je een waarde niet op uit je sessie.
snap niet echt wat er nu fout was.
Toevoeging op 16/03/2023 23:01:48:
sorry ja session, dat bedoel ik
maar ik heb nu weer wat dingen gedaan en nu werkt het ineens wel
zal wel iets niet goed gestaan hebben.
mee eens wat je zegd de 2de php had er eigenlijk ook even niet bij gemoeten.
bedankt.
Goed zo! Ook wil ik je attenderen op SQL-injection.
verbeteren is altijd beter. thxs
Dit heeft niks met professionele sites te maken. Het is altijd van belang.
Dat moet al best wel een tijd verplicht <*?php zijn. De verkorte versie is al een tijdje afgeschaft.
Dat geldt ook voor je echo commando's
dat mag dan naar keuze worden:
of
(dát mag dan weer wel in de korte versie)