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
Autore Titolo Forum Risposte Data
G [PHP] MODIFICARE DATI TABELLA CONTESTUALMENTE PHP 6
W Non riesco più a modificare i dati di una tabella da phpmyadmin MySQL 0
L Modificare dati tabella mysql PHP 2
D Modificare dati in un campo della tabella PHP 2
Z Istruzione SQL per modificare tabella (cambiare la tipologia dati di un campo) MS Access 0
M Php+MySql: Estrarre dati da tabella e consentire all'utente di modificare un valore 'in linea' PHP 6
F Modificare dati da una tabella PHP 3
K [ASP.Net] Utilizzare e modificare dati linq ASP.NET 0
S Modificare dati da più tabelle MySQL 6
C modificare dati specifici mysql con php PHP 2
C Pagina HTM connessa al DB access (non è possibile modificare/inserire dati) MS Access 0
S Come modificare i dati visualizzati di un record?? MySQL 0
I pagina per modificare dati inseriti in mysql PHP 43
I Modificare dati query PHP 6
A modificare i dati in un array PHP 3
M [cerco webmaster] sito web da modificare Offerte e Richieste di Lavoro e/o Collaborazione 0
G Come modificare un pdf in php PHP 1
napuleone modificare il valore dellascroll bar di webkit HTML e CSS 8
Shyson Modificare codice e creare link PHP 0
J Modificare panorami 360 ps 2020 Photoshop 0
napuleone modificare il contenitore di un div Javascript 2
napuleone modificare il contenitore di un div Javascript 1
D modificare questo codice per inserimento in text e non in tabella jQuery 1
C modificare sito in locale con dreamWeaver HTML e CSS 3
T Modificare ruolo utenti in fase di registrazione E-Commerce 0
M modificare un file .XML da database Sql PHP 13
S Modificare intestazione documento pdf con LO Draw Linux e Software 0
felino Radio button e Bootstrap: modificare il colore di default! HTML e CSS 1
Shyson Modificare funzione php PHP 15
W Modificare il Type di un Input box in javascript ovunque si trovi Javascript 0
F Modificare report di etichette di access con vba MS Access 0
D [PHP] Tabella: modificare direttamente i valori PHP 6
P [Woocommerce] Modificare il Bottone Checkout di Woocommerce in base alla categoria di prodotto E-Commerce 10
Q impossibile modificare un file ....... C/C++ 2
C [HTML] modificare la scritta della copyright HTML e CSS 2
Y [PHP] [HTML] Modificare i quadranti PHP 1
A [PHP] Modificare campo database in base alla scelta dell'utente PHP 2
V [WordPress] Come modificare link in tasto menu css WordPress 21
Y Modificare script php PHP 5
G Fullcalendar: modificare colore testo, backgroup e bordi per tutti gli eventi jQuery 3
paloppa Bootstrap.min.css modificare il file HTML e CSS 6
Merlina3377 [PHP] modificare file su form immagine thump PHP 1
G [HTML] Modificare ordine dei div in mobile responsive HTML e CSS 5
pfranco [PHP] Modificare pagina web online PHP 9
Shyson Modificare codice jQuery 0
A [Javascript] modificare il contenuto della barra indirizzi di un browser Javascript 1
asevenx modificare lista elementi togliendo l'elemento selezionato jQuery 1
Kolop "Modificare HTML" HTML e CSS 13
G Modificare navbar in base allo scroll jQuery 6
R [Photoshop] Modificare luminosità dei bordi in una foto Photoshop 2

Discussioni simili