Insert into database
Ik wil mijn data die ingelezen is, dmv een submit button onderaan de pagina , naar mijn database sturen(INSERT).
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
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
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'stplnr' => (int)$val->stplnr,
'errornr' => (int)$val->errornr,
'cyclusnr' => (int)$val->cyclusnr,
'pointnr' => (string)$val->pointnr,
'date' => (string)$val->date,
'time' => (string)$val->time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'stplX' => (float)$val->stplX,
'stplY' => (float)$val->stplY,
'stplZ' => (float)$val->stplZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
?>
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'stplnr' => (int)$val->stplnr,
'errornr' => (int)$val->errornr,
'cyclusnr' => (int)$val->cyclusnr,
'pointnr' => (string)$val->pointnr,
'date' => (string)$val->date,
'time' => (string)$val->time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'stplX' => (float)$val->stplX,
'stplY' => (float)$val->stplY,
'stplZ' => (float)$val->stplZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
?>
Wil je voortaan even aangeven wat er niet lukt?
Zeggen dat je iets wilt en dan niet aangeven wat er fout gaat, daar kunnen we niks mee.
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
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
<?php
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
# Require Page navigation script.
require('ssi/php/functions/pagenavigation.inc.php');
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
Select the right XML file here with the starting base points from the the project folder.<br /><br />
<form enctype="multipart/form-data" action="index.php?page=showxml" method="post">
After selecting the right file please click on : <i>Show XML data in table to continue....</i><br /><br />
<input name="file" type="file"><br /><br />
<input type="submit" name="submit" value="Show XML data in table">
</form>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
# Require Page navigation script.
require('ssi/php/functions/pagenavigation.inc.php');
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
Select the right XML file here with the starting base points from the the project folder.<br /><br />
<form enctype="multipart/form-data" action="index.php?page=showxml" method="post">
After selecting the right file please click on : <i>Show XML data in table to continue....</i><br /><br />
<input name="file" type="file"><br /><br />
<input type="submit" name="submit" value="Show XML data in table">
</form>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
Daar kies ik een xml bestand op mijn pc. Klik op de submit button en dan wordt er gelinkt naar
het volgende bestand dat heet showxml.php :
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
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
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'stplnr' => (int)$val->stplnr,
'errornr' => (int)$val->errornr,
'cyclusnr' => (int)$val->cyclusnr,
'pointnr' => (string)$val->pointnr,
'date' => (string)$val->date,
'time' => (string)$val->time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'stplX' => (float)$val->stplX,
'stplY' => (float)$val->stplY,
'stplZ' => (float)$val->stplZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
?>
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'stplnr' => (int)$val->stplnr,
'errornr' => (int)$val->errornr,
'cyclusnr' => (int)$val->cyclusnr,
'pointnr' => (string)$val->pointnr,
'date' => (string)$val->date,
'time' => (string)$val->time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'stplX' => (float)$val->stplX,
'stplY' => (float)$val->stplY,
'stplZ' => (float)$val->stplZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
?>
Hier wordt er gecontroleerd op juiste extensie bestand etc. Zo ja wordt de gegevens in een array geplaatst en weergegeven in een tabel.
Onder deze tabel heb ik dan een submit button die de data naar de database moet schrijven....
Tot zover lukt het me dus en dan houdt het beetje op.
Kunnen jullie mij hiermee op weg helpen dit op de lossen mijn ervaring in SQl is nog niet heel veel
Dank
Gewijzigd op 30/12/2013 15:19:31 door Rick Entonces
nu gebeurd dat al gelijk na de eerste keer dat ik op submit gedrukt heb!
Ik werk hier met 2 pagina's die allebei een submit knop hebben en met post iets meegeven.
De eerste knop is op application.php waarmee die andere pagina opend en de resultaten weergeeft.
Dan na visuele controle wil ik weer drukken op de submit button om ze naar de database te sturen.
Nu gaat dit een stap te vroeg zeg maar,
hoe kan ik dit oplossen
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
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
<?php
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'point_nr' => (string)$val->point_nr,
'point_date' => (string)$val->point_date,
'point_time' => (string)$val->point_time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'equip_id' => (int)$val->equip_id,
'cyclus_nr' => (int)$val->cyclus_nr,
'error_nr' => (int)$val->error_nr,
'stationX' => (float)$val->stationX,
'stationY' => (float)$val->stationY,
'stationZ' => (float)$val->stationZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
# InsertQuery.
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$rInsertQuery = "
INSERT INTO monitoring (point_nr,point_date,point_time,posX,posY,posZ,equip_id,cyclus_nr,error_nr,stationX,stationY,stationZ)
VALUES (
'".$point->point_nr."',
'".$point->point_date."',
'".$point->point_time."',
'".$point->posX."',
'".$point->posY."',
'".$point->posZ."',
'".$point->equip_id."',
'".$point->cyclus_nr."',
'".$point->error_nr."',
'".$point->stationX."',
'".$point->stationY."',
'".$point->stationZ."'
)";
# Setting up the MySQL database connection link.
$rDbLink = mysqli_connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
# Setting up characterset of MySQL database connection.
mysqli_set_charset($rDbLink,'utf8');
# MySQL Query Execute.
$rRecordSet = mysqli_query($rDbLink,$rInsertQuery);
if(!$rRecordSet) {
if(DEBUG_MODE) {
echo("Er ging iets fout met de query: ".mysqli_error($rDbLink)." (".$rInsertQuery.")");
}else {
echo("Er ging iets fout met de query");
}
}
# Close MySQL database connection
mysqli_close($rDbLink);
# Clear all other resources.
unset($rRecordSet,$rDbLink);
}
?>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'point_nr' => (string)$val->point_nr,
'point_date' => (string)$val->point_date,
'point_time' => (string)$val->point_time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'equip_id' => (int)$val->equip_id,
'cyclus_nr' => (int)$val->cyclus_nr,
'error_nr' => (int)$val->error_nr,
'stationX' => (float)$val->stationX,
'stationY' => (float)$val->stationY,
'stationZ' => (float)$val->stationZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" value="Send this data to the Database."></input><br />';
}
}
# InsertQuery.
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$rInsertQuery = "
INSERT INTO monitoring (point_nr,point_date,point_time,posX,posY,posZ,equip_id,cyclus_nr,error_nr,stationX,stationY,stationZ)
VALUES (
'".$point->point_nr."',
'".$point->point_date."',
'".$point->point_time."',
'".$point->posX."',
'".$point->posY."',
'".$point->posZ."',
'".$point->equip_id."',
'".$point->cyclus_nr."',
'".$point->error_nr."',
'".$point->stationX."',
'".$point->stationY."',
'".$point->stationZ."'
)";
# Setting up the MySQL database connection link.
$rDbLink = mysqli_connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
# Setting up characterset of MySQL database connection.
mysqli_set_charset($rDbLink,'utf8');
# MySQL Query Execute.
$rRecordSet = mysqli_query($rDbLink,$rInsertQuery);
if(!$rRecordSet) {
if(DEBUG_MODE) {
echo("Er ging iets fout met de query: ".mysqli_error($rDbLink)." (".$rInsertQuery.")");
}else {
echo("Er ging iets fout met de query");
}
}
# Close MySQL database connection
mysqli_close($rDbLink);
# Clear all other resources.
unset($rRecordSet,$rDbLink);
}
?>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
Gewijzigd op 30/12/2013 18:00:45 door Rick Entonces
Ja dus.
hoe kan ik dit oplossen dan ?
ik weet even niet, met unset misschien of?
Ik zie je na if($_SERVER['REQUEST_METHOD'] == 'POST') nergens iets gebruiken wat uit een POST zou moeten komen.
die zit dan in $_FILES[tmp_name] die open via xml functie en stop de waardes in een array.
Dan geef ik die waardes weer in een array.
dan wil ik dus die waardes uit die array naar me database sturen maar pas als ik op die submit knop gedrukt heb met de value "Send data to database"
Toevoeging op 30/12/2013 19:09:29:
Op dit moment heb ik de code zo en dan wordt in eerste instantie niks naar me databse gestuurd zoals ik wil.
De data wordt alleen weergegeven.
Dan klik op de knop om het naar mijn database te sturen maar dan gaat ie het begin van die pagina weer meenemen en blijft hij hangen op een controle functie die niet meer van toepassing is dan => op lijn 29 is dit.
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
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
<?php
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'point_nr' => (string)$val->point_nr,
'point_date' => (string)$val->point_date,
'point_time' => (string)$val->point_time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'equip_id' => (int)$val->equip_id,
'cyclus_nr' => (int)$val->cyclus_nr,
'error_nr' => (int)$val->error_nr,
'stationX' => (float)$val->stationX,
'stationY' => (float)$val->stationY,
'stationZ' => (float)$val->stationZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" name="insertsql" value="Send this data to the Database."></input><br />';
}
}
# Check if table is insert into database
if ($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_POST['insertsql'])) {
$rInsertQuery = "
INSERT INTO monitoring (point_nr,point_date,point_time,posX,posY,posZ,equip_id,cyclus_nr,error_nr,stationX,stationY,stationZ)
VALUES (
'".$point->point_nr."',
'".$point->point_date."',
'".$point->point_time."',
'".$point->posX."',
'".$point->posY."',
'".$point->posZ."',
'".$point->equip_id."',
'".$point->cyclus_nr."',
'".$point->error_nr."',
'".$point->stationX."',
'".$point->stationY."',
'".$point->stationZ."'
)";
# Setting up the MySQL database connection link.
$rDbLink = mysqli_connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
# Setting up characterset of MySQL database connection.
mysqli_set_charset($rDbLink,'utf8');
# MySQL Query Execute.
$rRecordSet = mysqli_query($rDbLink,$rInsertQuery);
if(!$rRecordSet) {
if(DEBUG_MODE) {
echo("Er ging iets fout met de query: ".mysqli_error($rDbLink)." (".$rInsertQuery.")");
}else {
echo("Er ging iets fout met de query");
}
}
# Close MySQL database connection
mysqli_close($rDbLink);
# Clear all other resources.
unset($rRecordSet,$rDbLink);
}
?>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
# Reports and Shows errors strictly.
error_reporting(E_ALL | E_STRICT);
?>
<!-- Start HTML5 Structure -->
<section class="courses">
<article>
<hgroup>
<h2><?php echo H2_LINK_1; ?></h2>
<h3><?php echo H3_LINK_1; ?></h3>
</hgroup><p><hr width="900" align="left">
<!-- End HTML 5 Structure -->
<?php
# Check if extention and MIME type is correct
# Array with permitted types.
$aType = array('.xml',);
# Array with permitted MIME types.
$aMime = array('text/xml',);
# Extension of the selected file.
$sExtension = strtolower(substr($_FILES['file']['name'], -4));
# Check if file is permitted.
if(!in_array($sExtension, $aType)) {
# Check for valid file.
echo 'An error has been occured while choosing your file.<br />';
echo 'Please choose a correct file.<br /><br />';
echo '<a href="index.php?page=application">Go Back....</a>';
} else {
# Check for valid MIME type.
if(!in_array($_FILES['file']['type'], $aMime)) {
# MIME type is not valid.
echo 'This is not an valid file.';
} else {
// Open selected XML
$xml = simplexml_load_file($_FILES['file']['tmp_name']);
$arr = array();
foreach($xml->point as $val) {
$rMonitoring[] = array(
'point_nr' => (string)$val->point_nr,
'point_date' => (string)$val->point_date,
'point_time' => (string)$val->point_time,
'posX' => (float)$val->posX,
'posY' => (float)$val->posY,
'posZ' => (float)$val->posZ,
'equip_id' => (int)$val->equip_id,
'cyclus_nr' => (int)$val->cyclus_nr,
'error_nr' => (int)$val->error_nr,
'stationX' => (float)$val->stationX,
'stationY' => (float)$val->stationY,
'stationZ' => (float)$val->stationZ);
}
// Dump variables en print to screen.
//var_dump($rMonitoring);
echo 'There are '.count($rMonitoring).' points measured in this baseline assesment.<br />';
echo 'When these results are good please insert them into the database on the bottom of this page.<br /><br />';
// Show XML results in table for first check before stored in database.
echo '<table>';
echo '<tr>';
echo '<th>Point Nr</th><th>Point Date</th><th>Point Time</th><th>Position X</th><th>Position Y</th><th>Position Z</th>';
echo '<th>Equipment Id</th><th>Cyclus Nr</th><th>Error Nr</th><th>Station X</th><th>Station Y</th><th>Station Z</th>';
echo '</tr>';
foreach ($xml->point as $point) {
echo '<tr>';
echo '<td>'.$point->point_nr.'</td><td>'.$point->point_date.'</td><td>'.$point->point_time.'</td><td>'.$point->posX.'</td><td>'.$point->posY.'</td><td>'.$point->posZ.'</td>';
echo '<td>'.$point->equip_id.'</td><td>'.$point->cyclus_nr.'</td><td>'.$point->error_nr.'</td><td>'.$point->stationX.'</td><td>'.$point->stationY.'</td><td>'.$point->stationZ.'</td>';
}
echo '</tr></th>';
echo '</table>';
echo '<br />';
echo '<form method="post">';
echo '<input type="submit" name="insertsql" value="Send this data to the Database."></input><br />';
}
}
# Check if table is insert into database
if ($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_POST['insertsql'])) {
$rInsertQuery = "
INSERT INTO monitoring (point_nr,point_date,point_time,posX,posY,posZ,equip_id,cyclus_nr,error_nr,stationX,stationY,stationZ)
VALUES (
'".$point->point_nr."',
'".$point->point_date."',
'".$point->point_time."',
'".$point->posX."',
'".$point->posY."',
'".$point->posZ."',
'".$point->equip_id."',
'".$point->cyclus_nr."',
'".$point->error_nr."',
'".$point->stationX."',
'".$point->stationY."',
'".$point->stationZ."'
)";
# Setting up the MySQL database connection link.
$rDbLink = mysqli_connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
# Setting up characterset of MySQL database connection.
mysqli_set_charset($rDbLink,'utf8');
# MySQL Query Execute.
$rRecordSet = mysqli_query($rDbLink,$rInsertQuery);
if(!$rRecordSet) {
if(DEBUG_MODE) {
echo("Er ging iets fout met de query: ".mysqli_error($rDbLink)." (".$rInsertQuery.")");
}else {
echo("Er ging iets fout met de query");
}
}
# Close MySQL database connection
mysqli_close($rDbLink);
# Clear all other resources.
unset($rRecordSet,$rDbLink);
}
?>
<!-- Start HTML5 Structure -->
</p>
</article>
</section>
<!-- End HTML 5 Structure -->
Zet bovenin een check voor het eerste formulier. Handel dat af en zet de inhoud van $_FILES in een session. Druk op de knop en check onderin of er op die bewuste knop is gedrukt. Dan zet je de inhoud van de session in de database.
dit stukje komt dan na mijn tabel met alle records neem ik aan.
Daarna checken of die button gedruk is en zo ja
insert into sql vanuit session variabelen
als ik het goed zie??
Uploaded files worden automatisch verwijderd als het script klaar is.
want ik krijg het niet voor mekaar , staar me kapot hahaha :)