Hvorfor virker dette ikke?
Jeg har dette script men kan ikke få det til at virke.Det har tidligere virket ved ikke hvad jeg har gjort siden det ikke virker mere.
Det er meningen at man uploader en xml fil i index.php?s=editor
Hvor efter den skal overføre filen til upload.php som gemmer filen i en mappe og vidresender til scripts_old.php som gemmer xml dataen i mySQL db
Men scriptet når ikke længere end upload.php hvad går der galt?
index.php
<?
session_start();
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/lightboxEx.css" type="text/css" rel="stylesheet" media="screen">
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>
<script src="js/effects.js" type="text/javascript"></script>
<script src="js/Sound.js" type="text/javascript"></script>
<script src="js/lightboxEx.js" type="text/javascript"></script>
<!-- Codes by Quackit.com -->
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=300,width=500,left=10,top=10,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
</script>
<title>XComCare :: Administration's system</title>
<style>
body{
background-color:#000000;
font-family:Arial,Verdana;
font-size:11px;
color:#ffffff;
}
td, p{
font-family:Arial,Verdana;
font-size:11px;
color:#ffffff;
}
a {
font-family:Arial,Verdana;
font-size:11px;
font-weight: bold;
color:#FF9900;
}
a.nav{
font-family:Arial,Verdana;
font-size:11px;
font-style:normal;
font-weight: bold;
color:#FFFFFF;
}
p {
font-family:Arial,Verdana;
font-size:11px;
margin:0px;
padding:2px;
}
input,textarea {
font-family:Arial,Verdana;
font-size:12px;
}
.posts{
background-color:#666666;
}
.postTitle{
background-color:#444444;
}
</style>
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle">
<table width="650" border="0" cellspacing="0" cellpadding="8" style="border-color:white; border-width:12px; border-style:solid">
<tr>
<td align="center" valign="middle" bgcolor="#333333">
<br>
<br>
<?
if(isset($_REQUEST['s'])) {
include($_REQUEST['s'] . '.php');
} else {
include('editor.php');
}
?>
<br>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
editor.php
<?
include('config.php');
@session_start();
//Checks if the user is logged in
if(!$_SESSION['news_module']) {
echo'<form method="post" action="login.php?return=' . rawurlencode($_SERVER['REQUEST_URI']) . '">
<table>
<tr>
<td><p>Brugernavn</p></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><p>Kodeord</p></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><input type="submit" value="Log på" /></td>
</tr>
</table>
</form>';
//The user is logged in
} else {
//A connection to MySQL is created
mysql_connect($mysql['host'],$mysql['user'],$mysql['password']) or die (mysql_error());
mysql_select_db($mysql['db']) or die (mysql_error());
$result = mysql_query("SELECT * FROM `ordre_module` ORDER BY `time` DESC");
if(mysql_errno() == 1146) {
mysql_query("CREATE TABLE IF NOT EXISTS `ordre_module` (
`id` int(11) NOT NULL auto_increment,
`OrdreNummer` varchar(10) NOT NULL default '',
`Dato` varchar(10) NOT NULL default '',
`kundenr` varchar(100) NOT NULL default '',
`FirmaNavn` varchar(100) NOT NULL default '',
`ATTnavn` varchar(100) NOT NULL default '',
`Adresse` varchar(100) NOT NULL default '',
`By` varchar(40) NOT NULL default '',
`PostNr` varchar(6) NOT NULL default '',
`Tlf` varchar(14) NOT NULL default '',
`Fax` varchar(14) NOT NULL default '',
`FirmaCvr` varchar(20) NOT NULL default '',
`Total` varchar(30) NOT NULL default '',
`Moms` varchar(30) NOT NULL default '',
`FederalTax` varchar(30) NOT NULL default '',
`Fragt` varchar(50) NOT NULL default '',
`SumTotal` varchar(50) NOT NULL default '',
`Ordre` varchar(10) NOT NULL default '',
`betalt` varchar(10) NOT NULL default '',
`VareNr_1` varchar(10) NOT NULL default '',
`Beskrivelse_1` text NOT NULL,
`Antal_1` varchar(10) NOT NULL default '',
`StkPris_1` varchar(30) NOT NULL default '',
`Pris_1` varchar(50) NOT NULL default '',
`VareNr_2` varchar(10) NOT NULL default '',
`Beskrivelse_2` text NOT NULL,
`Antal_2` varchar(10) NOT NULL default '',
`StkPris_2` varchar(30) NOT NULL default '',
`Pris_2` varchar(50) NOT NULL default '',
`VareNr_3` varchar(10) NOT NULL default '',
`Beskrivelse_3` text NOT NULL,
`Antal_3` varchar(10) NOT NULL default '',
`StkPris_3` varchar(30) NOT NULL default '',
`Pris_3` varchar(50) NOT NULL default '',
`VareNr_4` varchar(10) NOT NULL default '',
`Beskrivelse_4` text NOT NULL,
`Antal_4` varchar(10) NOT NULL default '',
`StkPris_4` varchar(30) NOT NULL default '',
`Pris_4` varchar(50) NOT NULL default '',
`VareNr_5` varchar(10) NOT NULL default '',
`Beskrivelse_5` text NOT NULL,
`Antal_5` varchar(10) NOT NULL default '',
`StkPris_5` varchar(30) NOT NULL default '',
`Pris_5` varchar(50) NOT NULL default '',
`VareNr_6` varchar(10) NOT NULL default '',
`Beskrivelse_6` text NOT NULL,
`Antal_6` varchar(10) NOT NULL default '',
`StkPris_6` varchar(30) NOT NULL default '',
`Pris_6` varchar(50) NOT NULL default '',
`VareNr_7` varchar(10) NOT NULL default '',
`Beskrivelse_7` text NOT NULL,
`Antal_7` varchar(10) NOT NULL default '',
`StkPris_7` varchar(30) NOT NULL default '',
`Pris_7` varchar(50) NOT NULL default '',
`VareNr_8` varchar(10) NOT NULL default '',
`Beskrivelse_8` text NOT NULL,
`Antal_8` varchar(10) NOT NULL default '',
`StkPris_8` varchar(30) NOT NULL default '',
`Pris_8` varchar(50) NOT NULL default '',
`VareNr_9` varchar(10) NOT NULL default '',
`Beskrivelse_9` text NOT NULL,
`Antal_9` varchar(10) NOT NULL default '',
`StkPris_9` varchar(30) NOT NULL default '',
`Pris_9` varchar(50) NOT NULL default '',
`VareNr_10` varchar(10) NOT NULL default '',
`Beskrivelse_10` text NOT NULL,
`Antal_10` varchar(10) NOT NULL default '',
`StkPris_10` varchar(30) NOT NULL default '',
`Pris_10` varchar(50) NOT NULL default '',
`VareNr_11` varchar(10) NOT NULL default '',
`Beskrivelse_11` text NOT NULL,
`Antal_11` varchar(10) NOT NULL default '',
`StkPris_11` varchar(30) NOT NULL default '',
`Pris_11` varchar(50) NOT NULL default '',
`VareNr_12` varchar(10) NOT NULL default '',
`Beskrivelse_12` text NOT NULL,
`Antal_12` varchar(10) NOT NULL default '',
`StkPris_12` varchar(30) NOT NULL default '',
`Pris_12` varchar(50) NOT NULL default '',
`VareNr_13` varchar(10) NOT NULL default '',
`Beskrivelse_13` text NOT NULL,
`Antal_13` varchar(10) NOT NULL default '',
`StkPris_13` varchar(30) NOT NULL default '',
`Pris_13` varchar(50) NOT NULL default '',
`VareNr_14` varchar(10) NOT NULL default '',
`Beskrivelse_14` text NOT NULL,
`Antal_14` varchar(10) NOT NULL default '',
`StkPris_14` varchar(30) NOT NULL default '',
`Pris_14` varchar(50) NOT NULL default '',
`VareNr_15` varchar(10) NOT NULL default '',
`Beskrivelse_15` text NOT NULL,
`Antal_15` varchar(10) NOT NULL default '',
`StkPris_15` varchar(30) NOT NULL default '',
`Pris_15` varchar(50) NOT NULL default '',
`edit_time` int(11) NOT NULL default '0',
`time` int(11) NOT NULL default '0',
`Kommentar` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;") or die (mysql_error());
echo'Databasen er nu oprettet!<br/><a href="' . $_SERVER['REQUEST_URI'] . '"> Opdater</a> venligst siden.';
exit;
} else {
//Form to adding news
include("navigation.php");
echo'
<div style="display:none;" id="addNews">
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
<table>
<tr>
<td><p>Send this file: <br><input name="userfile" type="file" />
<input type="submit" value="Send File" /></p></td>
</tr>
</table>
<br><br>
</form>
</div>';
//Form to edit news
if($_REQUEST['view']) {
$view_factura = mysql_query("SELECT * FROM `ordre_module` WHERE `id`=" . $_REQUEST['view']) or die (mysql_error() . ' in select from `ordre_module` in edit mode');
$view_factura = mysql_fetch_array($view_factura);
echo'<table>
<tr>
<td colspan="3">Firma</td>
<td colspan="3"><p><strong>' . $view_factura['FirmaNavn'] . '</strong></p></td>
</tr>
<tr>
<td colspan="3">Ordre Nr.</td>
<td colspan="3"><p><strong>' . $view_factura['OrdreNummer'] . '</strong></p></td>
</tr>
<tr>
<td colspan="3">Oprettelses dato</td>
<td colspan="3"><p><strong>' . strftime("%A %d. %B %Y",$row['time']) . '</strong></p></td>
</tr>
<tr>
<td>Vare nr.</td>
<td colspan="2">Beskrivelse</td>
<td>Antal</td>
<td>Pris stk.</td>
<td>Pris</td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_1'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_1'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_1'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_1'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_1'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_2'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_2'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_2'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_2'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_2'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_3'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_3'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_3'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_3'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_3'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_4'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_4'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_4'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_4'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_4'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_5'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_5'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_5'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_5'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_5'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_6'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_6'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_6'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_6'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_6'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_7'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_7'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_7'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_7'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_7'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_8'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_8'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_8'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_8'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_8'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_9'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_9'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_9'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_9'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_9'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_10'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_10'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_10'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_10'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_10'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_11'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_11'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_11'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_11'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_11'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_12'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_12'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_12'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_12'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_12'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_13'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_13'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_13'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_13'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_13'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_14'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_14'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_14'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_14'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_14'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td><p><strong>' . $view_factura['VareNr_15'] . '</strong></p></td>
<td colspan="2"><p><strong>' . $view_factura['Beskrivelse_15'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Antal_15'] . '</strong></p></td>
<td><p><strong>' . $view_factura['StkPris_15'] . '</strong></p></td>
<td><p><strong>' . $view_factura['Pris_15'] . '</strong></p></td>
<td> </td>
</tr>
<tr>
<td>Kommentar</td>
<td colspan="3" rowspan="4"><p><strong>' . $view_factura['Kommentar'] . '</strong></p></td>
<td>Total</td>
<td><p><strong>' . $view_factura['Total'] . '</strong></p></td>
</tr>
<tr>
<td> </td>
<td>Uden Moms</td>
<td><p><strong>' . $view_factura['Moms'] . '</strong></p></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><p><strong> </strong></p></td>
</tr>
<tr>
<td> </td>
<td>Fragt</td>
<td><p><strong>' . $view_factura['Fragt'] . '</strong></p></td>
</tr>
<tr>
<td colspan="2"> </td>
<td>total</td>
<td><p><strong>' . $view_factura['SumTotal'] . '</strong></p></td>
</tr>
</table>
<br><br>';
}
//Prints existing news
echo'<table cellspacing="5" width="540" bgcolor="#4f4f4f">
<tr>
<td width="110px"><p><strong>Overskrift</strong></p></td>
<td width="280px"><p><strong>Dato</strong></p></td>
<td width="140px"><p><strong>Slet</strong></p></td>
</tr>';
while($row = mysql_fetch_array($result)) {
echo'<tr>
<td style="background-color:#6a6a6a;"><p>
<a href="' . $_SERVER['SCRIPT_NAME'] . '?view=' . $row['id'] . '">'.$row['FirmaNavn'].' '.$row['OrdreNummer'].'</a>
</p></td>
<td style="background-color:#6a6a6a;"><p>
' . strftime("%A %d. %B %Y",$row['time']) . '
</p></td>
<td style="background-color:#6a6a6a;"><p>
<a href="#" onclick="if(confirm(\'Er du sikker på, at du vil slette?\')) {document.location.href=\'scripts.php?delete=' . $row['id'] . '\';}">Slet</a>
</p></td>
</tr>';
}
echo'</table>';
}
}
?>
upload.php
<?php
include('config.php');
@session_start();
//Checks if the user is logged in
if(!$_SESSION['news_module']) {
echo'<form method="post" action="login.php?action=upload&return=' . rawurlencode($_SERVER['REQUEST_URI']) . '">
<table>
<tr>
<td><p>Brugernavn</p></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><p>Kodeord</p></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><input type="submit" value="Log på" /></td>
</tr>
</table>
</form>';
} else {
$source = 'regnskab/xml/'; //Fra mappe
$uploadfile = $source . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
header("Location: /hardlife/scripts_old.php?action=upload" );
} else {
echo "Upload failed";
}
}
?>
scripts_old.php
<?
session_start();
include('config.php');
mysql_connect($mysql['host'],$mysql['user'],$mysql['password']) or die (mysql_error());
mysql_select_db($mysql['db']) or die (mysql_error());
$source = 'regnskab/xml/'; //Fra mappe
$directory = 'regnskab/DB/'; //Til mappe
foreach ( glob('./'.$source.'*.xml') as $file ){
CreateAndRunSQL( $file );
}
function CreateAndRunSQL( $f ) {
$xmlDoc = new DOMDocument();
$xmlDoc->load($f);
$vareCount=0;
$fields = Array();
$vars = '';
$values = '';
$xmlLines = $xmlDoc->firstChild->childNodes;
foreach ($xmlLines as $node) {
if ($node->nodeType==3) continue;
$pling = "'";
$nodeName = $node->nodeName;
if ( $nodeName == 'Total' ||
$nodeName == 'Antal' ) {
$pling = '';
}
if ( $nodeName == 'OrdreNummer' ) {
$Ordre = $node->nodeValue;
}
$vars .= ($vars == '')?'':', ';
$vars .= '`'.$nodeName;
if ( $nodeName == 'VareNr')
$vareCount++;
if ( $nodeName == 'VareNr' ||
$nodeName == 'Beskrivelse' ||
$nodeName == 'Antal' ||
$nodeName == 'StkPris' ||
$nodeName == 'Pris' ) {
$vars .= '_'.$vareCount;
}
$values .= ($values == '')?'':', ';
$values .= $pling.$node->nodeValue.$pling;
$vars = $vars.'`';
}
$values = $values.", '".time()."'";
$stmt = 'insert into ordre_module ('.$vars.', `time`) values ('.$values.');';
$query = mysql_query($stmt) or die (mysql_error());
if ($query){
$destination = 'regnskab/DB/Faktura_'.$Ordre.'.xml';
$data = file_get_contents($f);
$handle = fopen($destination, "w");
fwrite($handle, $data);
fclose($handle);
unlink($f);
header("Location: /hardlife/index.php?s=editor" );
} else {
echo "Sending fejlede<br>";
}
//Hvis den blev udført skal filen flyttes til arkivfolder
//Hvis den ikke blev udført skal fejlmelding echo'es ud
}
?>