Ciao a tutti ragazzi, avevo pensato di aggiungere righe ad un tabella tramite un bottone, e cercando su internet ho trovato questo :
solo che non mi funziona in questa pagina, credo di sbagliare(sicuramente) qualcosa io nell'inserimento di js nel mio codice php :
HTML:
<!doctype html>
<head>
</head>
<body>
<script type="text/javascript">
function aggiungiRiga(id_table)
{
var table = document.getElementById(id_table);
var tbody = table.getElementsByTagName('tbody')[0];
var colonne = table.getElementsByTagName('th').length;
var tr = document.createElement('tr');
for(var i= 0; i<colonne; i++)
{
var td = document.createElement('td');
var tx = document.createTextNode(prompt("Inserisci testo per cella "+(i+1),""));
td.appendChild(tx);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
</script>
</body>
</html>
solo che non mi funziona in questa pagina, credo di sbagliare(sicuramente) qualcosa io nell'inserimento di js nel mio codice php :
PHP:
>
<title>Inserimento</title>
<head>
<title>Inserimento</title>
<style>
table, th, td
{
border: 1px solid black;
}
</style>
</head>
<body>
<script language='javascript' src='Inserisciriga.js'></script>
<h1>Inserimento</h1>
<table id='my_table' class='tabella' style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Filiale</th>
<th>Ufficio</th>
<th>Utente</th>
<th>Tipo</th>
<th>Marca</th>
<th>Modello</th>
<th>Matricola</th>
<th>Note</th>
<th>DataDDT</th>
<th>DDT</th>
<th>Fornitore</th>
<th>ACQNOL</th>
<th>Scadenza</th>
</tr>
</thead>
<tbody>
</tbody>
<a href='Eliminazione.php'><input type="submit" name="Eliminazione" value="Elimina un record nel database" /></a>
<a href='Visualizza.php'><input type="submit" name="Visualizza" value="Ricerca un record nel database" /></a>
<a href='Modifica.php'><input type="submit" name="Modifica" value="Modifica un record nel database" /></a>
<a href='Ricerca.php'><input type="submit" name="Ricerca" value="Ricerca un record nel database" /></a>
<form action="" method="post">
</br>Inserisci una filiale <input type="text" name="Filiale" /> <br/>
Inserisci l'ufficio della filiale<input type="text" name="Ufficio" /> <br/>
inserisci l'utente dell'hardware<input type="text" name="Utente" /> <br/>
Inserisci il Tipo dell'hardware<input type="text" name="Tipo" /> <br/>
Inserisci la marca dell'hardware<input type="text" name="Marca" /> <br/>
Inserisci il modello dell'hardware<input type="text" name="Modello" /> <br/>
Inserisci il numero di serie dell'hardware<input type="text" name="Matricola" /> <br/>
Note<input type="text" name="Note" /> <br/>
Inserisci la data DDT<input type="text" name="DataDDT" /> <br/>
Inserisci la DDT<input type="text" name="DDT" /> <br/>
Inserisci il fornitore dell' hardware<input type="text" name="Fornitore" /> <br/>
acquistato o noleggiato ?<input type="text" name="ACQNOL" /> <br/>
Inserisci la data di scadenza della garanzia<input type="text" name="Scadenza" /> <br/>
<input type="submit" name="Inserisci" value="Inserisci" />
<input type='button' value='Aggiungiriga' name='Aggiungiriga' onClick="aggiungiRiga('my_table')" />
<?php
try
{
$user="root";
$pass="";
$dbh = new PDO('mysql:host=localhost;dbname=hardwarea', $user, $pass);
if(isset($_POST['Inserisci']))
{
$stmt = $dbh->prepare("INSERT INTO gestione (Filiale,Ufficio,Utente,Tipo,Marca,Modello,Matricola,Note,DataDDT,DDT,Fornitore,ACQNOL,Scadenza) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
$stmt->bindParam(1, $Filiale);
$stmt->bindParam(2, $Ufficio);
$stmt->bindParam(3, $Utenti);
$stmt->bindParam(4, $Tipo);
$stmt->bindParam(5, $Marca);
$stmt->bindParam(6, $Modello);
$stmt->bindParam(7, $Matricola);
$stmt->bindParam(8, $Note);
$stmt->bindParam(9, $DataDDT);
$stmt->bindParam(10, $DDT);
$stmt->bindParam(11, $Fornitore);
$stmt->bindParam(12, $ACQNOL);
$stmt->bindParam(13, $Scadenza);
if(isset($_POST['Filiale']))
{
$Filiale = $_POST['Filiale'];
}
if(isset($_POST['Ufficio']))
{
$Ufficio = $_POST['Ufficio'];
}
if(isset($_POST['Utenti']))
{
$Utenti = $_POST['Utenti'];
}
if(isset($_POST['Tipo']))
{
$Tipo = $_POST['Tipo'];
}
if(isset($_POST['Marca']))
{
$Marca = $_POST['Marca'];
}
if(isset($_POST['Modello']))
{
$Modello = $_POST['Modello'];
}
if(isset($_POST['Matricola']))
{
$Matricola = $_POST['Matricola'];
}
if(isset($_POST['Note']))
{
$Note = $_POST['Note'];
}
if(isset($_POST['DataDDT']))
{
$DataDDT = $_POST['DataDDT'];
}
if(isset($_POST['DDT']))
{
$DDT = $_POST['DDT'];
}
if(isset($_POST['Fornitore']))
{
$Fornitore = $_POST['Fornitore'];
}
if(isset($_POST['ACQNOL']))
{
$ACQNOL = $_POST['ACQNOL'];
}
if(isset($_POST['Scadenza']))
{
$Scadenza = $_POST['Scadenza'];
}
$stmt->execute();
}
if(isset($_POST['Aggiungiriga']))
{
echo "<script>aggiungiRiga()</script>";
}
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
<?php
try
{
$user="root";
$pass="";
$dbh = mysql_connect("localhost","root",$pass);
mysql_select_db('hardwarea') or die(mysql_error());
$stmt = ("Select * from gestione");
$ris= mysql_query($stmt) or die($stmt."<br/><br/>".mysql_error());
while($rigo=mysql_fetch_array($ris))
{
echo" <tr> <td> " . $rigo['ID'] . " </td> <td> " . $rigo['Filiale'] . " </td> <td> " . $rigo['Ufficio'] . " </td> <td> " . $rigo['Utente'] . " </td> <td> " . $rigo['Tipo'] . " </td> <td> " . $rigo['Marca'] . " </td> <td> " . $rigo['Modello'] . " </td> <td> " . $rigo['Matricola'] . " </td> <td> " . $rigo['Note'] . " </td> <td> " . $rigo['DataDDT'] . " </td> <td> " . $rigo['DDT'] . " </td><td> " . $rigo['Fornitore'] . " </td> <td> " . $rigo['ACQNOL'] . " </td> <td> " . $rigo['Scadenza'] . " </tr>";
}
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</form>
</body>
</html>
Ultima modifica: