Modificare dati in tabella csv da php

Ivano Cardassi

Nuovo Utente
23 Nov 2013
14
0
0
Magione (Italia), Italy
Buonasera ragazzi,
non ho avito una dimenticanza, ma non ho trovato la parte "presentati", per cui, chiedo scusa comunque, lo faccio qui.

Ho un piccolo problema ma che non riesco a risolvere da 3 giorni.

Ho una tabella csv che da php riesco benissimo a visualizzare, cancellare la riga, scrivere sul database, ma non riesco a capire come modificare la riga.
siccome il titolare dell'azienda ha sempre fretta e il lavoro doveva essere pronto già da 2 mesi... ho preso il codice già pronto. Ho provato a contattare il creatore (tedesco) che però non risponde all'email. Secondo me dovrebbe essere una cavolata.

vi posto il codice. grazie infinite a chi può aiutare a non sentire il capo urlare.... (ivano)

PHP:
$products = new MyCSV("products");
if (isset($_REQUEST['action']) && $_REQUEST['action'] == "update")
{
    $products->update($_REQUEST['id']);
    $products->write();
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == "delete")
{
    $products->delete($_REQUEST['id']);
    $products->write();
}
// Check if something was submitted in the form.
if (!empty($_POST['name']))
{
    // Add a new row to the table. If the file does not exist and the table
    // contains no fields, this call also creates the fields. Not that all
    // TM::MyCSV tables will contain an 'id' column. Every row you add to the
    // table will get a new ID (similar to AUTO_INCREMENT from MySQL).
    $products->insert(array(
        'name'  => stripslashes($_POST['name']),
		'modello'  => stripslashes($_POST['modello']),
		'all'  => stripslashes($_POST['all']),
		'tipo'  => stripslashes($_POST['tipo']),
		'col'  => stripslashes($_POST['col']),
		'acc'  => stripslashes($_POST['acc']),
		'alim'  => stripslashes($_POST['alim']),
		'km'  => stripslashes($_POST['km']),
		'anno'  => stripslashes($_POST['anno']),
		'rif'  => stripslashes($_POST['rif']),
		'ex'  => stripslashes($_POST['ex']),
        'vendita' => stripslashes($_POST['vendita']),
		'targa'  => stripslashes($_POST['targa']),
		'carico'  => stripslashes($_POST['carico']),
		'ubi'  => stripslashes($_POST['ubi']),
		'soc'  => stripslashes($_POST['soc']),
		'note'  => stripslashes($_POST['note']),
    ));
    // Save the whole table to disk.
    $products->write();
}

// Check if the user clicked one of the table headers.
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : "";
$desc = isset($_REQUEST['desc']) ? " DESC" : "";

// It's a very bad idea to use something that the user entered in your SQL
// statements. This leads to SQL insertions. We do a translation instead. All
// invalid values, hacking attempts and so on will fall back to the default
// behaviour.
switch ($sort)
{
    case "name":
        // Order by name in ascending or descending order. Two products with the
        // same name will be ordered by price.
        $products->sort("name SORT_LOCALE_STRING SORT_NULL $desc, carico SORT_NUMERIC");
        break;
    case "carico":
        // Order by price using a numeric comparison. SORT_NULL moves products
        // without a price to the bottom.
        $products->sort("carico SORT_NUMERIC SORT_NULL $desc, name SORT_LOCALE_STRING");
        break;
    default:
        // Ordered by ID ("unordered") by default.
        if (!$desc)
        {
            $products->ksort();
        }
        else
        {
            $products->krsort();
        }
        break;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="de" xml:lang="de" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Stock Auto</title>
<meta name="robots" content="none" />
<style type="text/css">

/* A little bit of CSS to make the example look nice. */

body
{
	color: #333;
	font-family: Verdana, sans-serif;
}
form div{
	margin: 0.1em 0;
}
label
{
	cursor: pointer;
	float: left;
	padding-right: 0.3em;
	text-align: right;
	width: 10em;
}
table
{
	border-collapse: collapse;
	border-spacing: 0;
	empty-cells: show;
}
th, td
{
	border-bottom: 1px solid #CCC;
	padding: 0.5em 0.5em;
	text-align: left;
	vertical-align: top;
	font-size: 13px;
}
th, th a
{
	background: #666;
	color: #FFF;
}

</style>
</head>
<body>

<h1>Stock in rientro</h1>
<a href="logout.php">Logout</a>  
<!-- In most cases I use my TM::Apeform class to create such forms. In this
     case, I don't want another dependency in this example script. -->

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
	<fieldset>
		<legend>Aggiungi auto</legend>
		<div style="float:left;">
			<label for="name">Marca:</label>
			<input id="name" name="name" type="text" />
		</div>
        <div style="float:left;">
			<label for="modello">Modello:</label>
			<input id="modello" name="modello" type="text" />
		</div>
        <div style="float:left;">
			<label for="all">Allestimento:</label>
			<input id="all" name="all" type="text" />
		</div>
        <div style="float:left;">
			<label for="tipo">Tipo:</label>
			<input id="tipo" name="tipo" type="text" />
		</div>
        <div style="float:left;">
			<label for="col">Colore:</label>
			<input id="col" name="col" type="text" />
		</div>
        <div style="float:left;">
			<label for="acc">Accessori:</label>
			<input id="acc" name="acc" type="text" />
		</div>
        <div style="float:left;">
			<label for="alim">Alim:</label>
			<input id="alim" name="alim" type="text" />
		</div>
        <div style="float:left;">
			<label for="km">KM:</label>
			<input id="km" name="km" type="text" />
		</div>
        <div style="float:left;">
			<label for="anno">Anno:</label>
			<input id="anno" name="anno" type="text" />
		</div>
        <div style="float:left;">
			<label for="rif">Rif. Int.:</label>
			<input id="rif" name="rif" type="text" />
		</div>
        <div style="float:left;">
			<label for="ex">Propr.:</label>
			<input id="ex" name="ex" type="text" />
		</div>
        <div style="float:left;">
			<label for="vendita">Vendita:</label>
			<input id="vendita" name="vendita" type="text" />
		</div>
        <div style="float:left;">
			<label for="targa">Targa:</label>
			<input id="targa" name="targa" type="text" />
		</div>
        <div style="float:left;">
			<label for="carico">Carico:</label>
			<input id="carico" name="carico" type="text" />
		</div>
        <div style="float:left;">
			<label for="ubi">Ubic:</label>
			<input id="ubi" name="ubi" type="text" />
		</div>
        <div style="float:left;">
			<label for="soc">Societa':</label>
			<input id="soc" name="soc" type="text" />
		</div>
        <div style="float:left;">
			<label for="note">Note:</label>
			<input id="note" name="note" type="text" />
		</div>
		<div style="float:left;">
			<label>&nbsp;</label>
			<input type="submit" value="Aggiungi" />
		</div>
        
	</fieldset>
</form>

<table>
	<tr>
		<th>ID</th>
		<th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "name" && !$desc) echo '&amp;desc'?>">Marca</a><?php
			if ($sort == "name") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "modello" && !$desc) echo '&amp;desc'?>">Modello</a><?php
			if ($sort == "modello") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "all" && !$desc) echo '&amp;desc'?>">Allestimento</a><?php
			if ($sort == "all") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "tipo" && !$desc) echo '&amp;desc'?>">Tipo</a><?php
			if ($sort == "tipo") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "col" && !$desc) echo '&amp;desc'?>">Colore</a><?php
			if ($sort == "col") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "acc" && !$desc) echo '&amp;desc'?>">Accessori</a><?php
			if ($sort == "acc") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "alim" && !$desc) echo '&amp;desc'?>">Alim.</a><?php
			if ($sort == "alim") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "km" && !$desc) echo '&amp;desc'?>">Km</a><?php
			if ($sort == "km") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "anno" && !$desc) echo '&amp;desc'?>">Anno</a><?php
			if ($sort == "anno") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "rif" && !$desc) echo '&amp;desc'?>">Rif.Int.</a><?php
			if ($sort == "rif") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "ex" && !$desc) echo '&amp;desc'?>">Proprietario</a><?php
			if ($sort == "ex") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "vendita" && !$desc) echo '&amp;desc'?>">Vendita</a><?php
			if ($sort == "vendita") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "targa" && !$desc) echo '&amp;desc'?>">Targa</a><?php
			if ($sort == "targa") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "carico" && !$desc) echo '&amp;desc'?>">Carico</a><?php
			if ($sort == "carico") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "ubi" && !$desc) echo '&amp;desc'?>">Ubic.</a><?php
			if ($sort == "ubi") echo $desc ? '▼' : '▲'?>
		</th>
        <th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=name<?php
			if ($sort == "soc" && !$desc) echo '&amp;desc'?>">Società</a><?php
			if ($sort == "soc") echo $desc ? '▼' : '▲'?>
		</th>
		<th>
			<a href="<?php echo $_SERVER['PHP_SELF']?>?sort=price<?php
			if ($sort == "note" && !$desc) echo '&amp;desc'?>">Note</a><?php
			if ($sort == "note") echo $desc ? '▼' : '▲'?>
		</th>
		<th></th>
		</tr>

<?php

// Sometimes it is easier to use echo statements instead of the mixed HTML and
// PHP syntax above. I use both depending on the amount of HTML code.

while ($product = $products->each())
{
    echo '<tr>';
    echo '<td>' . htmlspecialchars($product['id']) . '</td>';
    echo '<td>' . htmlspecialchars($product['name']) . '</td>';
	echo '<td>' . htmlspecialchars($product['modello']) . '</td>';
	echo '<td>' . htmlspecialchars($product['all']) . '</td>';
	echo '<td>' . htmlspecialchars($product['tipo']) . '</td>';
	echo '<td>' . htmlspecialchars($product['col']) . '</td>';
	echo '<td>' . htmlspecialchars($product['acc']) . '</td>';
	echo '<td>' . htmlspecialchars($product['alim']) . '</td>';
	echo '<td>' . htmlspecialchars($product['km']) . '</td>';
	echo '<td>' . htmlspecialchars($product['anno']) . '</td>';
	echo '<td>' . htmlspecialchars($product['rif']) . '</td>';
	echo '<td>' . htmlspecialchars($product['ex']) . '</td>';
    echo '<td>';
    if (empty($product['vendita']))
    {
        echo '&mdash;';
    }
    else
    {
        echo htmlspecialchars($product['vendita']) . ' &euro;';
    }
	echo '<td>' . htmlspecialchars($product['targa']) . '</td>';
	echo '<td>';
	if (empty($product['carico']))
    {
        echo '&mdash;';
    }
    else
    {
        echo htmlspecialchars($product['carico']) . ' &euro;';
    }
	echo '<td>' . htmlspecialchars($product['ubi']) . '</td>';
	echo '<td>' . htmlspecialchars($product['soc']) . '</td>';
	echo '<td>' . htmlspecialchars($product['note']) . '</td>';
    echo '</td>';
    echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?action=delete&amp;id=' .
        htmlspecialchars($product['id']) . '">Delete</a></td>';
		echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?action=update&amp;id=' .
        htmlspecialchars($product['id']) . '">Modifica</a></td>';
    echo '</tr>';
	
}

?>

</table>

</body>
</html>
 

Discussioni simili