Update record in mysqli

marini91

Nuovo Utente
1 Mar 2017
2
0
1
33
Buonasera ragazzi,
è la prima volta che programmo con php. Sto cercando di aggiornare i campi "date" di un record di una tabella mysqli ma dopo aver inserito le due date nel form e cliccato sul pulsante ricevo questo errore :

Notice: Undefined variable: mysqli in /home/labisacc/public_html/tmp/src_1ee2ea98e4c8b4a316799c97c43ec135 on line 18

Fatal error: Call to a member function prepare() on null in /home/labisacc/public_html/tmp/src_1ee2ea98e4c8b4a316799c97c43ec135 on line 18

PHP:
<html>
<head>
<title>Update Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['add'])) {
$con = mysqli_connect("xxxxxxxx","xxxxxxxx","xxxxxx","xxxxxx") or die("Some error occurred during connection " . mysqli_error($con));

// Parametri

$datainiziososp = $_POST['datainiziososp'];
$datafinesosp = $_POST['datafinesosp'];

$statement = $mysqli->prepare("UPDATE jhost_eshop_customers SET DatIniSosp=?, DatFinSosp=? WHERE customer_id=302");

$statement->bind_param('ss', $datainiziososp->format('Y-m-d'), $datafinesosp->format('Y-m-d'));
$results = $statement->execute();
if($results){
print 'Success! record updated';
}else{
print 'Error : ('. $mysqli->errno .') '. $mysqli->error;
}

// Chiudi connessione
mysqli_close($con);

}else{
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border = "0" cellspacing = "1"
 cellpadding = "2">

<tr>
<td width = "200">Data inizio sospensione</td>
<td><input name = "datainiziososp" type = "date"
id = "datainiziososp"></td>
 </tr>

 <tr>
<td width = "200">Data fine sospensione</td>
<td><input name = "datafinesosp" type = "date"
id = "datafinesosp"></td>
 </tr>

 <tr>
<td width = "100"> </td>
<td> </td>
 </tr>

 <tr>
<td width = "100"> </td>
<td>
<input name = "add" type = "submit" id = "add"
value = "Sospendi">
</td>
 </tr>

</table>
</form>

<?php
 }

 ?>

</body>
</html>

Potete aiutarmi ?

Grazie mille per l'attenzione
 
Ultima modifica di un moderatore:

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
così a prima vista stai mescolando la programmazione procedurale con quella ad oggetti
sostituisci
PHP:
$con = mysqli_connect("xxxxxxxx","xxxxxxxx","xxxxxx","xxxxxx")..
con
PHP:
$mysqli = new mysqli('xxxxxxxx', 'xxxxxxxx', 'xxxxxxxx', 'xxxxxxxx');
 
Discussioni simili
Autore Titolo Forum Risposte Data
A Esecuzione di una Update di singoli record PHP 3
I update record in mysql anche con riga vuota PHP 3
T Update di più record PHP 0
T update PHP 2
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
elpirata Update dinamico informazioni scritte in una pagina php jQuery 11
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
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

Discussioni simili