Update dinamico informazioni scritte in una pagina php

elpirata

Utente Attivo
18 Mar 2009
264
7
18
Buongiorno a tutti,
ho realizzato una pagina in php che verifica in un database mysql se nel mese corrente ci sono dei veicoli che hanno la revisione in scadenza e mostra a video i risultati ottenuti. Ho poi aggiunto accanto ad ogni record estratto un campo denominato "Note" che viene utilizzato dal personale addetto al contatto con il cliente per riportare l'esito della telefonata.

Ora il mio problema è che non so come assegnare al button che ho inserito a fondo pagina una funzione che permetta al click del mouse l'update nel database delle informazioni inserite dall'utente nel campo "Note"

Questo il codice della pagina php:
Codice:
<form method="POST" action="scadenza_revisione.php" id="inseriscinote" >
<?php
date_default_timezone_set('Europe/Rome');
require_once('function/date_day.php');

$veicolo='UNDEF';
$targa='UNDEF';
$cliente='UNDEF';
$tel='UNDEF';
$dtscrev='UNDEF';
$noterev='UNDEF';
$where='';

//var_dump($_GET['tipo']);
//exit;

if(isset($_GET['tipo']))$tipo = trim(strip_tags(stripslashes($_GET['tipo'])));
else echo 'Attenzione è stato riscontrato un errore contattare amministratore';

if ($tipo == "daeseguire"){
$where = "WHERE YEAR(dtscrev) = YEAR(NOW()) AND MONTH(dtscrev)= MONTH(NOW()) AND DAY(dtscrev) >= DAY(NOW())";

}elseif($tipo == "scadute"){
$where = "WHERE dtscrev < NOW()-1 AND dtscrev <> '0000-00-00'";
}

$query = "SELECT * FROM commesse $where GROUP BY targa ORDER BY dtscrev ASC LIMIT 20";
$oggetto =$mysqli->query($query);
$count = mysqli_num_rows($oggetto);

if ($count == 0) {

echo "<div class = 'container-ricerca-nulla'>";
echo "<div class ='row'><p class='btn btn-danger center-button'>Non sono presenti revisioni da eseguire</p></div>";
echo "</div>";

}else{

echo "<div class ='container-appuntamento'>";
echo "<table class='table table-striped table-responsive'>";
echo "<tr>";
echo "<th style='color:green'>Veicolo</th>";
echo "<th style='color:green'>Targa</th>";
echo "<th style='color:green'>Cliente</th>";
echo "<th style='color:green'>Telefono</th>";
echo "<th style='color:green'>Data Scadenza<br>Revisione</th>";
echo "<th style='color:red'>Note</th>";
echo "</tr>";


while($scorri_oggetto=$oggetto->fetch_assoc()){
$veicolo = mysqli_real_escape_string($mysqli, $scorri_oggetto['veicolo']);
$targa = mysqli_real_escape_string($mysqli, $scorri_oggetto['targa']);
$cliente = mysqli_real_escape_string($mysqli, $scorri_oggetto['cliente']);
$tel = mysqli_real_escape_string($mysqli, $scorri_oggetto['tel']);
$dtscrev = mysqli_real_escape_string($mysqli, $scorri_oggetto['dtscrev']);
$noterev = mysqli_real_escape_string($mysqli, $scorri_oggetto['noterev']);


/* FILTRI e CONVERSIONI SULLE VARIABILI POST */
$cliente = trim(strip_tags(stripslashes($cliente)));
$cliente = str_replace('\r\n' , '<br>', $cliente);
$cliente = stripslashes($cliente);
$cliente = wordwrap($cliente,18,"<br>"); //MANDO A CAPO OGNI 18 CARATTERI

$noterev = trim(strip_tags(stripslashes($noterev)));
$noterev = str_replace('\r\n' , '<br>', $noterev);
$noterev = stripslashes($noterev);


$veicolo = trim(strip_tags(stripslashes($veicolo)));
$veicolo = str_replace('\r\n' , '<br>', $veicolo);

$dtscrev = strtotime($dtscrev);
$dtscrev = date('d/m/Y', $dtscrev);
?>

<tr>
<td style="text-align:left;"><?php echo $veicolo; ?></td>
<td style="text-align:left;"><?php echo $targa; ?></td>
<td style="text-align:left;"><?php echo $cliente; ?></td>
<td style="text-align:left;"><?php echo $tel; ?></td>
<td><?php echo data_it($dtscrev);?></td>
<td><input name="noterev" type="text" value="<?php echo $scorri_oggetto['noterev']; ?>" size="63" maxlength="200" /></td>
</tr>

<?php
}
echo "</table>";
echo "</div>";
}
?>
<div class="container-fluid">
<tr>
<td><button type="button" class="btn btn-success btn-bd btn-block"><input type="hidden" name="aggiorna_noterev" value="ok"><input type="hidden" value="<?php echo $scorri_oggetto['id_com']; ?>" name="id_com" >Memorizza nel database le note inserite</button></td>
</tr>
</div>

</form>

<?php
if (isset($_POST['aggiorna_noterev'])){
$query="UPDATE commesse
SET noterev='".$_POST['noterev']."'
WHERE id_com='".$_POST['id_com']."' ";
$oggetto =$mysqli->query($query);
}
?>


Questa invece la pagina con il relativo pulsante che non riesco a far funzionare


Naturalmente l'update dovrebbe avvenire sulla stessa pagina e magari dopo l'update un alert a video informa l'utente che le informazioni sono state memorizzate con successo.

Confido in un vostro supporto perchè non so davvero dove andare a parare.

Grazie anticipatamente a tutti
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Cioè "dinamicamente con Jquery" intendi che vuoi che i dati vengano salvati senza che si ricarichi la pagina?
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Prima di tutto, se non lo hai già fatto, devi includere jquery, inserendo questo nell'head:
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Ora aggiungi un campo hidden con id="totale" e value="<?php echo $count;?>".
Subito prima dell'inizio del while aggiungi $i=0; mentre subito dopo l'inizio del while aggiungi $i++;
Poi nel campo input della nota aggiungi:
PHP:
id="nota<?php echo $i;?>"
Ora controlla nella sorgente del codice html che i vari campi nota della tabella si chiamino nota1, nota2, ecc.
Se è tutto ok, prosegui cosi:
Aggiungi uno script del genere, nell'head della pagina:
HTML:
<script>
$(document).ready(function(){
$("#id_bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var note = [];
for(n=1;n<totale;n++){
note.push($("#nota"+n).val());
}
$.ajax({
        type:'POST',
        url:"modifica.php",
dataType: 'JSON',
        data:{'notes':note},
        success:function(msg){
            if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
        },
        error:function(){
            alert('Errore.');
        }
    })
});
});
</script>
Infine devi creare un file modifica.php in cui ricevi i dati con POST e li inserisci nel database:
PHP:
$note = $_POST['notes'];
foreach($note as $nota){
$query = mysqli_query(...); //qui metti la query che modifica la riga del db
}
if($query){
echo "ok";
}else{
echo "errore";
}
 

elpirata

Utente Attivo
18 Mar 2009
264
7
18
Potresti farmi un esempio di come integrare il tuo codice nel mio ?

PHP:
<form method="POST" action="scadenza_revisione.php" id="inseriscinote" >
<?php
date_default_timezone_set('Europe/Rome');
require_once('function/date_day.php');

$veicolo='UNDEF';
$targa='UNDEF';
$cliente='UNDEF';
$tel='UNDEF';
$dtscrev='UNDEF';
$noterev='UNDEF';
$where='';

//var_dump($_GET['tipo']);
//exit;

if(isset($_GET['tipo']))$tipo = trim(strip_tags(stripslashes($_GET['tipo'])));
else echo 'Attenzione è stato riscontrato un errore contattare amministratore';

if ($tipo == "daeseguire"){
$where = "WHERE YEAR(dtscrev) = YEAR(NOW()) AND MONTH(dtscrev)= MONTH(NOW()) AND DAY(dtscrev) >= DAY(NOW())";

}elseif($tipo == "scadute"){
$where = "WHERE dtscrev < NOW()-1 AND dtscrev <> '0000-00-00'";
}

$query = "SELECT * FROM commesse $where GROUP BY targa ORDER BY dtscrev ASC LIMIT 20";
$oggetto =$mysqli->query($query);
$count = mysqli_num_rows($oggetto);

if ($count == 0) {

echo "<div class = 'container-ricerca-nulla'>";
echo "<div class ='row'><p class='btn btn-danger center-button'>Non sono presenti revisioni da eseguire</p></div>";
echo "</div>";

}else{

echo "<div class ='container-appuntamento'>";
echo "<table class='table table-striped table-responsive'>";
echo "<tr>";
echo "<th style='color:green'>Veicolo</th>";
echo "<th style='color:green'>Targa</th>";
echo "<th style='color:green'>Cliente</th>";
echo "<th style='color:green'>Telefono</th>";
echo "<th style='color:green'>Data Scadenza<br>Revisione</th>";
echo "<th style='color:red'>Note</th>";
echo "</tr>";


while($scorri_oggetto=$oggetto->fetch_assoc()){
$veicolo = mysqli_real_escape_string($mysqli, $scorri_oggetto['veicolo']);
$targa = mysqli_real_escape_string($mysqli, $scorri_oggetto['targa']);
$cliente = mysqli_real_escape_string($mysqli, $scorri_oggetto['cliente']);
$tel = mysqli_real_escape_string($mysqli, $scorri_oggetto['tel']);
$dtscrev = mysqli_real_escape_string($mysqli, $scorri_oggetto['dtscrev']);
$noterev = mysqli_real_escape_string($mysqli, $scorri_oggetto['noterev']);


/* FILTRI e CONVERSIONI SULLE VARIABILI POST */
$cliente = trim(strip_tags(stripslashes($cliente)));
$cliente = str_replace('\r\n' , '<br>', $cliente);
$cliente = stripslashes($cliente);
$cliente = wordwrap($cliente,18,"<br>"); //MANDO A CAPO OGNI 18 CARATTERI

$noterev = trim(strip_tags(stripslashes($noterev)));
$noterev = str_replace('\r\n' , '<br>', $noterev);
$noterev = stripslashes($noterev);


$veicolo = trim(strip_tags(stripslashes($veicolo)));
$veicolo = str_replace('\r\n' , '<br>', $veicolo);

$dtscrev = strtotime($dtscrev);
$dtscrev = date('d/m/Y', $dtscrev);
?>

<tr>
<td style="text-align:left;"><?php echo $veicolo; ?></td>
<td style="text-align:left;"><?php echo $targa; ?></td>
<td style="text-align:left;"><?php echo $cliente; ?></td>
<td style="text-align:left;"><?php echo $tel; ?></td>
<td><?php echo data_it($dtscrev);?></td>
<td><input name="noterev" type="text" value="<?php echo $scorri_oggetto['noterev']; ?>" size="63" maxlength="200" /></td>
</tr>

<?php
}
echo "</table>";
echo "</div>";
}
?>
<div class="container-fluid">
<tr>
<td><button type="button" class="btn btn-success btn-bd btn-block"><input type="hidden" name="aggiorna_noterev" value="ok"><input type="hidden" value="<?php echo $scorri_oggetto['id_com']; ?>" name="id_com" >Memorizza nel database le note inserite</button></td>
</tr>
</div>

</form>

<?php
if (isset($_POST['aggiorna_noterev'])){
$query="UPDATE commesse
SET noterev='".$_POST['noterev']."'
WHERE id_com='".$_POST['id_com']."' ";
$oggetto =$mysqli->query($query);
}
?>

Poi tu mi scrivi:
Ora controlla nella sorgente del codice html che i vari campi nota della tabella si chiamino nota1, nota2, ecc.

Nel database mysql ho un unico campo che è di tipo VARCHAR(200) e si chiama "noterev"
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Nel database mysql ho un unico campo che è di tipo VARCHAR(200) e si chiama "noterev"
si intendevo i campi input della tabella html

PHP:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#id_bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var array_note=new Array();
    for (var i=1; i<=totale; i++){
        array_note[i]=[];
        array_note[i]['targa']=$("#targa"+i).val();
        array_note[i]['nota']=$("#nota"+i).val();
    }

    var send_array = JSON.stringify(array_note);
$.ajax({
type:'POST',
url:"modifica.php",
dataType: 'JSON',
data:{'notes':send_array},
success:function(msg){
if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
},
error:function(){
alert('Errore.');
}
})
});
});
</script>

</head>

<form method="POST" action="scadenza_revisione.php" id="inseriscinote" >
<?php
date_default_timezone_set('Europe/Rome');
require_once('function/date_day.php');

$veicolo='UNDEF';
$targa='UNDEF';
$cliente='UNDEF';
$tel='UNDEF';
$dtscrev='UNDEF';
$noterev='UNDEF';
$where='';

//var_dump($_GET['tipo']);
//exit;

if(isset($_GET['tipo']))$tipo = trim(strip_tags(stripslashes($_GET['tipo'])));
else echo 'Attenzione è stato riscontrato un errore contattare amministratore';

if ($tipo == "daeseguire"){
$where = "WHERE YEAR(dtscrev) = YEAR(NOW()) AND MONTH(dtscrev)= MONTH(NOW()) AND DAY(dtscrev) >= DAY(NOW())";

}elseif($tipo == "scadute"){
$where = "WHERE dtscrev < NOW()-1 AND dtscrev <> '0000-00-00'";
}

$query = "SELECT * FROM commesse $where GROUP BY targa ORDER BY dtscrev ASC LIMIT 20";
$oggetto =$mysqli->query($query);
$count = mysqli_num_rows($oggetto);

if ($count == 0) {

echo "<div class = 'container-ricerca-nulla'>";
echo "<div class ='row'><p class='btn btn-danger center-button'>Non sono presenti revisioni da eseguire</p></div>";
echo "</div>";

}else{

echo "<div class ='container-appuntamento'>";
echo "<table class='table table-striped table-responsive'>";
echo "<tr>";
echo "<th style='color:green'>Veicolo</th>";
echo "<th style='color:green'>Targa</th>";
echo "<th style='color:green'>Cliente</th>";
echo "<th style='color:green'>Telefono</th>";
echo "<th style='color:green'>Data Scadenza<br>Revisione</th>";
echo "<th style='color:red'>Note</th>";
echo "</tr>";

$i=0;
while($scorri_oggetto=$oggetto->fetch_assoc()){
$i++;
$veicolo = mysqli_real_escape_string($mysqli, $scorri_oggetto['veicolo']);
$targa = mysqli_real_escape_string($mysqli, $scorri_oggetto['targa']);
$cliente = mysqli_real_escape_string($mysqli, $scorri_oggetto['cliente']);
$tel = mysqli_real_escape_string($mysqli, $scorri_oggetto['tel']);
$dtscrev = mysqli_real_escape_string($mysqli, $scorri_oggetto['dtscrev']);
$noterev = mysqli_real_escape_string($mysqli, $scorri_oggetto['noterev']);


/* FILTRI e CONVERSIONI SULLE VARIABILI POST */
$cliente = trim(strip_tags(stripslashes($cliente)));
$cliente = str_replace('\r\n' , '<br>', $cliente);
$cliente = stripslashes($cliente);
$cliente = wordwrap($cliente,18,"<br>"); //MANDO A CAPO OGNI 18 CARATTERI

$noterev = trim(strip_tags(stripslashes($noterev)));
$noterev = str_replace('\r\n' , '<br>', $noterev);
$noterev = stripslashes($noterev);


$veicolo = trim(strip_tags(stripslashes($veicolo)));
$veicolo = str_replace('\r\n' , '<br>', $veicolo);

$dtscrev = strtotime($dtscrev);
$dtscrev = date('d/m/Y', $dtscrev);
?>

<tr>
<td style="text-align:left;"><?php echo $veicolo; ?></td>
<td style="text-align:left;"><?php echo $targa; ?></td>
<td style="text-align:left;"><?php echo $cliente; ?></td>
<td style="text-align:left;"><?php echo $tel; ?></td>
<td><?php echo data_it($dtscrev);?></td>
<td><input name="noterev" id="note<?php echo $i;?>" type="text" value="<?php echo $scorri_oggetto['noterev']; ?>" size="63" maxlength="200" /></td>
<input type="hidden" id="targa<?php echo $i;?>" value="<?php echo $targa;?>">
</tr>
<input type="hidden" id="totale" value="<?php echo $count;?>">
<?php
}
echo "</table>";
echo "</div>";
}
?>
<div class="container-fluid">
<tr>
<td><button type="button" id="bottone" class="btn btn-success btn-bd btn-block"><input type="hidden" name="aggiorna_noterev" value="ok"><input type="hidden" value="<?php echo $scorri_oggetto['id_com']; ?>" name="id_com" >Memorizza nel database le note inserite</button></td>
</tr>
</div>

</form>
modifica.php:
PHP:
$data = json_decode(stripslashes($_REQUEST['notes']));
foreach($data as $a){
$targa = $a->targa;
$nota = $a->nota;
    $query=mysqli_query($conn, "UPDATE commesse SET notarev='$nota' WHERE targa='$targa'");
}
if($query){
echo "ok";
}else{
echo "errore";
}
 

elpirata

Utente Attivo
18 Mar 2009
264
7
18
Buongiorno,
ho provato ad eseguire il codice da te proposto e anzitutto prima di proseguire ti ringrazio infinitamente.

Quando clicco sul button per memorizzare la nota, ottengo l'alert con la scritta

Ti posto il codice cosi come è adesso:

Pagina scadenza_revisione.php
PHP:
<script>
$(document).ready(function(){
$("#bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var array_note=new Array();
    for (var i=1; i<=totale; i++){
        array_note[i]=[];
        array_note[i]['targa']=$("#targa"+i).val();
        array_note[i]['noterev']=$("#noterev"+i).val();
    }

    var send_array = JSON.stringify(array_note);
$.ajax({
type:'POST',
url:"modifica.php",
dataType: 'JSON',
data:{'notes':send_array},
success:function(msg){
if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
},
error:function(){
alert('Errore.');
}
})
});
});
</script>

<form method="POST" action="scadenza_revisione.php" id="inseriscinote" >
<?php
date_default_timezone_set('Europe/Rome');
require_once('function/date_day.php');

$veicolo='UNDEF';
$targa='UNDEF';
$cliente='UNDEF';
$tel='UNDEF';
$dtscrev='UNDEF';
$noterev='UNDEF';
$where='';

//var_dump($_GET['tipo']);
//exit;

if(isset($_GET['tipo']))$tipo = trim(strip_tags(stripslashes($_GET['tipo'])));
else echo 'Attenzione è stato riscontrato un errore contattare amministratore';

if ($tipo == "daeseguire"){
$where = "WHERE YEAR(dtscrev) = YEAR(NOW()) AND MONTH(dtscrev)= MONTH(NOW()) AND DAY(dtscrev) >= DAY(NOW())";

}elseif($tipo == "scadute"){
$where = "WHERE dtscrev < NOW()-1 AND dtscrev <> '0000-00-00'";
}

$query = "SELECT * FROM commesse $where GROUP BY targa ORDER BY dtscrev ASC LIMIT 20";
$oggetto =$mysqli->query($query);
$count = mysqli_num_rows($oggetto);

if ($count == 0) {

echo "<div class = 'container-ricerca-nulla'>";
echo "<div class ='row'><p class='btn btn-danger center-button'>Non sono presenti revisioni da eseguire</p></div>";
echo "</div>";

}else{

echo "<div class ='container-appuntamento'>";
echo "<table class='table table-striped table-responsive'>";
echo "<tr>";
echo "<th style='color:green'>Veicolo</th>";
echo "<th style='color:green'>Targa</th>";
echo "<th style='color:green'>Cliente</th>";
echo "<th style='color:green'>Telefono</th>";
echo "<th style='color:green'>Data Scadenza<br>Revisione</th>";
echo "<th style='color:red'>Note</th>";
echo "</tr>";

$i=0;
while($scorri_oggetto=$oggetto->fetch_assoc()){
$i++;
$veicolo = mysqli_real_escape_string($mysqli, $scorri_oggetto['veicolo']);
$targa = mysqli_real_escape_string($mysqli, $scorri_oggetto['targa']);
$cliente = mysqli_real_escape_string($mysqli, $scorri_oggetto['cliente']);
$tel = mysqli_real_escape_string($mysqli, $scorri_oggetto['tel']);
$dtscrev = mysqli_real_escape_string($mysqli, $scorri_oggetto['dtscrev']);
$noterev = mysqli_real_escape_string($mysqli, $scorri_oggetto['noterev']);


/* FILTRI e CONVERSIONI SULLE VARIABILI POST */
$cliente = trim(strip_tags(stripslashes($cliente)));
$cliente = str_replace('\r\n' , '<br>', $cliente);
$cliente = stripslashes($cliente);
$cliente = wordwrap($cliente,18,"<br>"); //MANDO A CAPO OGNI 18 CARATTERI

$noterev = trim(strip_tags(stripslashes($noterev)));
$noterev = str_replace('\r\n' , '<br>', $noterev);
$noterev = stripslashes($noterev);


$veicolo = trim(strip_tags(stripslashes($veicolo)));
$veicolo = str_replace('\r\n' , '<br>', $veicolo);

$dtscrev = strtotime($dtscrev);
$dtscrev = date('d/m/Y', $dtscrev);
?>

<tr>
<td style="text-align:left;"><?php echo $veicolo; ?></td>
<td style="text-align:left;"><?php echo $targa; ?></td>
<td style="text-align:left;"><?php echo $cliente; ?></td>
<td style="text-align:left;"><?php echo $tel; ?></td>
<td><?php echo data_it($dtscrev);?></td>
<td><input name="noterev" id="noterev<?php echo $i;?>" type="text" value="<?php echo $scorri_oggetto['noterev']; ?>" size="63" maxlength="200" /></td>
<input type="hidden" id="targa<?php echo $i;?>" value="<?php echo $targa;?>">
</tr>
<input type="hidden" id="totale" value="<?php echo $count;?>">

<?php
}
echo "</table>";
echo "</div>";
}
?>
<div class="container-fluid">
<tr>
<td><button type="button" id="bottone" class="btn btn-success btn-bd btn-block"><input type="hidden" name="aggiorna_noterev" value="ok"><input type="hidden" value="<?php echo $scorri_oggetto['id_com']; ?>" name="id_com" >Memorizza nel database le note inserite</button></td>
</tr>
</div>
</form>

Pagina modifica.php

PHP:
<?php
$host = 'localhost';
$user = 'usermysql';
$pass = 'passwordmysql';
$db = 'databasemysql';
$mysqli = new mysqli("$host", "$user", "$pass", "$db");
$data = json_decode(stripslashes($_REQUEST['notes']));
foreach($data as $a){
$targa = $a->targa;
$noterev = $a->noterev;
$query=mysqli_query($mysqli, "UPDATE commesse SET noterev='$noterev' WHERE targa='$targa'");
}
if($query){
echo "ok";
}else{
echo "errore";
}
?>
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Come prima cosa guarda la sorgente della pagina (Ctrl+U) e controlla che i vari input delle note abbiano id="nota1", nota2, nota3, ecc. Poi se è corretto, prova a fare qualche alert, tipo alert(send_array). La pagina è online? Se si, provo a vedere il codice e faccio qualche prova
 

elpirata

Utente Attivo
18 Mar 2009
264
7
18
Come prima cosa guarda la sorgente della pagina (Ctrl+U) e controlla che i vari input delle note abbiano id="nota1", nota2, nota3, ecc.

I campi a me non si chiamano il nome nota ma noterev

Poi se è corretto, prova a fare qualche alert, tipo alert(send_array). La pagina è online? Se si, provo a vedere il codice e faccio qualche prova
Non so dove andare ad inserire gli alert


Questo il codice sorgente della pagina CTRL + U, il campo viene correttamente incrementato (in totale l'esempio estrare 14 record ed il conto torna, ma nel codice sotto riportato ne ho inseriti solo 3 per comodità)

HTML:
<!doctype html>
<html lang="it">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Gestionale Officina">

    <title>Gestione Officina</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/table.css" rel="stylesheet" media="screen" />
    <link href="css/home.css" rel="stylesheet" media="screen" />
    <link href="css/form.css" rel="stylesheet" media="screen" />
    <link href="css/font-awesome.min.css" rel="stylesheet" media="screen" />
    <link href='https://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!--INIZIO SCRIPT-->
    <script type="text/javascript" src="http://ff.kis.v2.scr.kaspersky-labs.com/FD126C42-EBFA-4E12-B309-BB3FDD723AC1/main.js?attr=g8KFiG_7u1me8ZP9GjqnR6KbTLUsnQycdZmAHjS9qszqIciu7hswuAQvsr2FjfrONJBokNHZ0cgWj96qgjqb-Cmpfm8Vv88DW1cTMsOxadUoFc2aTbZnqhwuk_pRNXugm8DZcuAztRnqPW8GZNaLKg" charset="UTF-8"></script><script type="text/javascript" src="js/somma.js"></script>
    <script type="text/javascript" src="js/datapicker.js"></script>
    <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.10.4.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-i18n.js"></script>
    <!--FINE SCRIPT-->

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <script type="text/javascript" src="inc/jquery.ui.datepicker-it.js"></script>
    <script type="text/javascript" src="js/qcTimepicker.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
   

<script type="text/javascript">
   $(function() {
   var date = $('#datepicker').datepicker({ dateFormat: 'dd/mm/yy' }).val();
   var date = $('#datepicker1').datepicker({ dateFormat: 'dd/mm/yy' }).val();
   var date = $('#datepicker2').datepicker({ dateFormat: 'dd/mm/yy' }).val();
   //var minDate: new Date(, , );
   });
</script>


<script type="text/javascript">
   $(document).ready(function() {
   $('.timepicker').qcTimepicker();
   });
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

<body>

    <!-- Page Content -->
   
    <div class="container white">
        <div class="header">
            <div class="logo"><a href="index.php?page=home">Gestione Officina</a></div>
        </div>

        <div class="row">

        <script>
$(document).ready(function(){
$("#bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var array_note=new Array();
    for (var i=1; i<=totale; i++){
        array_note[i]=[];
        array_note[i]['targa']=$("#targa"+i).val();
        array_note[i]['noterev']=$("#noterev"+i).val();
    }

    var send_array = JSON.stringify(array_note);
$.ajax({
type:'POST',
url:"modifica.php",
dataType: 'JSON',
data:{'notes':send_array},
success:function(msg){
if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
},
error:function(){
alert('Errore.');
}
})
});
});
</script>

<form method="POST" action="scadenza_revisione.php" id="inseriscinote" >
<div class ='container-appuntamento'><table class='table table-striped table-responsive'><tr><th style='color:green'>Veicolo</th><th style='color:green'>Targa</th><th style='color:green'>Cliente</th><th style='color:green'>Telefono</th><th style='color:green'>Data Scadenza<br>Revisione</th><th style='color:red'>Note</th></tr>
<tr>
<td style="text-align:left;">FIAT PANDA</td>
<td style="text-align:left;">AA123AA</td>
<td style="text-align:left;">ROSSI MARIO</td>
<td style="text-align:left;">33312312320</td>
<td>Giovedi<br>13/08/2020</td>
<td><input name="noterev" id="noterev1" type="text" value="" size="63" maxlength="200" /></td>
<input type="hidden" id="targa1" value=AA123AA">
</tr>
<input type="hidden" id="totale" value="14">


<tr>
<td style="text-align:left;">OPEL CORSA</td>
<td style="text-align:left;">BB123AA</td>
<td style="text-align:left;">BIANCHI MARIO</td>
<td style="text-align:left;">33312412321</td>
<td>Lunedi<br>17/08/2020</td>
<td><input name="noterev" id="noterev2" type="text" value="" size="63" maxlength="200" /></td>
<input type="hidden" id="targa2" value="BB123AA">
</tr>
<input type="hidden" id="totale" value="14">


<tr>
<td style="text-align:left;">LANCIA VOYAGER</td>
<td style="text-align:left;">CC123AA</td>
<td style="text-align:left;">VERDE GIULIO</td>
<td style="text-align:left;">00000</td>
<td>Martedi<br>18/08/2020</td>
<td><input name="noterev" id="noterev3" type="text" value="" size="63" maxlength="200" /></td>
<input type="hidden" id="targa3" value="CC123AA">
</tr>
<input type="hidden" id="totale" value="14">

ecc. ecc.

</table></div><div class="container-fluid">
<tr>
<td><button type="button" id="bottone" class="btn btn-success btn-bd btn-block"><input type="hidden" name="aggiorna_noterev" value="ok"><input type="hidden" value="" name="id_com" >Memorizza nel database le note inserite</button></td>
</tr>
</div>

</form>

<!--?php
if (isset($_POST['aggiorna_noterev'])){
$query="UPDATE commesse
SET noterev='".$_POST['noterev']."'
WHERE id_com='".$_POST['id_com']."' ";
$oggetto =$mysqli->query($query);
}
?-->
        </div>

        <hr>

           
                <div class="footer">
                    <div class="footer-text"> Testo del footer <br />
                    Gestione Officina - Copyright &copy; 2020 - All rights reserved.
                    </div>
                </div>
           
    </div>
   

   
    <!-- /.container -->

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

</body>
</html>
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Questo l'ho testato e mi funziona:
HTML:
<script>
$(document).ready(function(){
$("#bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var array_note=[];
    for (var i=1; i<=totale; i++){
    var targ = $("#targa"+i).val();
    var not = $("#noterev"+i).val();
        array_note.push({
        targa: targ,
        nota: not
        });
    }

    var send_array = JSON.stringify(array_note);
    alert(send_array);
$.ajax({
type:'POST',
url:"modifica.php",
dataType: 'JSON',
data:{'notes':send_array},
success:function(msg){
if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
},
error:function(){
alert('Errore.');
}
})
});
});
</script>
 

elpirata

Utente Attivo
18 Mar 2009
264
7
18
Questo l'ho testato e mi funziona:
HTML:
<script>
$(document).ready(function(){
$("#bottone").click(function(){ //al posto di id_bottone metti l'id del tuo tasto di invio
var totale = $("#totale").val();
var array_note=[];
    for (var i=1; i<=totale; i++){
    var targ = $("#targa"+i).val();
    var not = $("#noterev"+i).val();
        array_note.push({
        targa: targ,
        nota: not
        });
    }

    var send_array = JSON.stringify(array_note);
    alert(send_array);
$.ajax({
type:'POST',
url:"modifica.php",
dataType: 'JSON',
data:{'notes':send_array},
success:function(msg){
if(msg == "ok"){
//codice per mostrare che l'inserimento è riuscito
}else{
//codice per mostrare che l'inserimento non è riuscito
}
},
error:function(){
alert('Errore.');
}
})
});
});
</script>

Al click sul pulsante a me compare, prima una box con tutte queste info e fin qui tutto ok, perchè prende correttamente in input sia la targa che la relativa nota

Codice:
[{"targa":"AA123AA","nota":"Questa è una nota di test"},{"targa":"AA124AA","nota":""},{"targa":"AA125AA","nota":""},{"targa":"AA126AA","nota":""},{"targa":"AA127AA","nota":""},{"targa":"AA128AA","nota":""},{"targa":"AA129AA","nota":""},{"targa":"AA130AA","nota":""},{"targa":"AA131AA","nota":""},{"targa":"AA132AA","nota":""},{"targa":"AA133AA","nota":""},{"targa":"AA134AA","nota":""},{"targa":"AA135AA","nota":""},{"targa":"AA136AA","nota":""}]

Per cuorisità, considerato che a me non funziona, la query della pagina modifica.php scritta in questo modo secondo te è corretta ?

PHP:
<?php
$host = 'localhost';
$user = 'usermysql';
$pass = 'passwordmysql';
$db = 'databasemysql';
$mysqli = new mysqli("$host", "$user", "$pass", "$db");
$data = json_decode(stripslashes($_REQUEST['notes']));
foreach($data as $a){
$targa = $a->targa;
$noterev = $a->noterev;
$query=mysqli_query($mysqli, "UPDATE commesse SET noterev='$noterev' WHERE targa='$targa'");
}
if($query){
echo "ok";
}else{
echo "errore";
}
?>
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
Prova cosi:
PHP:
<?php
$host = 'localhost';
$user = 'usermysql';
$pass = 'passwordmysql';
$db = 'databasemysql';
$mysqli = new mysqli("$host", "$user", "$pass", "$db");
$data = $_REQUEST['notes'];
$array = json_decode($data, true);
for($i=0;$i<count($array);$i++){
$targa = $array[$i]['targa'];
$nota = $array[$i]['nota'];
$query=mysqli_query($mysqli, "UPDATE commesse SET noterev='$nota' WHERE targa='$targa'");
}
echo "ok";
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
C UPDATE dinamico campo vuoto del DB PHP 9
K Problema form update PHP 2
M query update e delete PHP 0
N MAX() + ADD_DATE - per update su Mysql MySQL 0
felino Windows 7: errore 80072EFE su Windows Update Windows e Software 1
A pulsante di update campo mysql con javascript Javascript 2
MarcoGrazia ON DUPLICATE KEY ma in realtà non UPDATE mai PHP 17
R Errore UPDATE tabella mysql PHP 1
M Update con condizione SQL PHP 7
M Problema su update di 3 tabelle PHP 1
G Problema update di un database PHP 0
L update tabelle in php mysql [risolto] PHP 6
P update records PHP 2
B [MySQL] Problemino con UPDATE MySQL 10
M [PHP] Query UPDATE che non mi aggiorna campi seconda tabella PHP 3
felino [Windows 8.1] Windows Update non funziona correttamente Windows e Software 3
P [PHP] INSERT e UPDATE PHP 1
elpirata [MYSQL] Schedulare evento per update del campo data su tabella MySQL 0
D [ASP] Mysql insert e update Classic ASP 2
M UPDATE non aggiorna db se lo inserisco in un ciclo Database 1
Monital [PHP] query update e select insieme ma frazionando l'arrray PHP 12
D [PHP] Update non trasferisce condizione where PHP 1
L [PHP] Errore UPDATE su tabella DB PHP 22
giancadeejay [PHP] istruzione UPDATE SQL PHP 2
giancadeejay [PHP] UPDATE DATO , SE ESISTE IN DB .. PHP 14
C What is Latest update on SEO SEO e Posizionamento 1
K Non trovo l'errore! PDO MYSQL UPDATE PHP 2
marini91 Update record in mysqli PHP 1
R [MySQL] SQL UPDATE INNER JOIN MySQL 5
giancadeejay [PHP] Update tabella da file csv PHP 3
webmachine [PHP] SELECT, UPDATE VERIFICARNE IL RISULTATO PHP 2
cris8380 [PHP] Update in search. PHP 16
filippino Google Update fine Aprile 2016: Bruschi cambiamenti SERP SEO e Posizionamento 3
pup3770 Riprendere da db e UPDATE PHP 9
N Problema funzione UPDATE PHP 9
C Problema con update di un file PHP 6
L Upload immagine e update dati DB PHP 2
K Problema con update di un database in un ciclo Classic ASP 1
C Problema con Update di una tabella di un db PHP 3
L update MySQL 2
G Update file con javascript per controllo estensioni Javascript 5
P Problemi UPDATE PHP 1
MarcoGrazia [PDO][MySQL] L'update non avviene PHP 1
R Update PHP dalla 5.3.3 alla 5.3.4 PHP 0
S Insert into....on duplicate key update MySQL 2
1 Errore UPDATE, DELETE MS Access 16
Z Google Update del 7 Agosto 2014 SEO e Posizionamento 1
M Messaggio di errore su pulsante update PHP 0
L DML: utente con permessi di UPDATE con WHERE ha bisogno di privilegi di SELECT? PHP 1
I Update multiple PHP 3

Discussioni simili