-
Ho provato e mi dice:
Warning: main(): Couldn't fetch mysqli_stmt in /membri/paolin/sign-invio-prova.php on line 231
Grazie per aver firmato il Libro
...
ho provato ad aggiungere 2 a $stmt
modificando così il codice:
Codice PHP:
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt->insert_id ."<br />";
}
}
ora non dà nessun messaggio di errore, ma solo
Grazie per aver firmato il Libro
....
e più sotto la solita tabella...
Però nella Tabella Guestbook non inserisce nulla.
Cordiali saluti
-
Si è giusto, ho riguardato il codice che aveva messo nel post 73 e effetivamente a variabile per la query record è $stmt2 e non $stmt. vanno corrette col 2 affected_rows e insert_id.
Nella query record in bind_param sostituisca sssssss con issssss.
Cordiali saluti.
-
Grazie, ho corretto. Nessun errore compare,
ma resta il fatto che NON INSERISCE il messaggio nella tabella Guestbook.
Posto l'intero codice per verifica:
Codice PHP:
<?php
function detect_cyr_utf8($content)
{
return preg_match('/
[78]\d/', mb_encode_numericentity($content, array(0x0, 0x2FFFF, 0, 0xFFFF), 'UTF-8'));
}
function mysqli_result($result,$row=0,$field=0){
$numrows = mysqli_num_rows($result);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($result,$row);
$resrow = (is_numeric($field)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result);
if (isset($resrow[$field])){return $resrow[$field];}
}
return false;
}
error_reporting(E_ALL);
@session_start(); // start session if not started yet
if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);
?>
<br> <img src='imm/stop.gif'><br>...
<?php
}
else {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);
$nome=$_POST["fullname"];
$aaemail=$_POST["email"];
//$commento=htmlspecialchars ($_POST["comments"], ENT_QUOTES);
$commento=$_POST["comments"]; // l'uso di htmlspecialchars crea caratteri che spesso nei browser vengono visualizzati male
$localita=$_POST["location"];
$indirizzoip=$_SERVER['REMOTE_ADDR'];
//$tempo=getdate("d/m/Y H:i:s")); // non commntato da GraphOGLRisorse
//$tempo=getdate(); // non commntato da GraphOGLRisorse
//$tempo=getTimestamp(); // non commntato da GraphOGLRisorse
$tempo = date("Y-m-d H:i:s");
//$tempo = timestamp($current_date); // non commntato da GraphOGLRisorse
if (stristr($aaemail, 'smith'))
{
?>
<img src='imm/stop.gif'><br>...
<?php
}
else
{
if (empty($commento))
{
?>
<img src='imm/stop.gif'><br>...
<?php
}
else
{
$trovato=0;
$num_parole=0;
$stringhe= array('cialis', 'viagra', 'http','www','penis','girl');
while (($num_parole < count($stringhe)) and ($trovato==0))
{
If (stristr($commento, $stringhe[$num_parole])) $trovato=1;
$num_parole++;
}
if ($trovato==1)
{
?>
<img src='imm/stop.gif'><br>...
<?php
}
else
{
if (detect_cyr_utf8($commento))
{
?>
<img src='imm/stop.gif'><br>...
<?php
}
else
{
?>
<?php
$db_host = "localhost";
$db_user = "xxxxxx";
$db_name = "my_xxxxxx";
//$db = mysql_connect($db_host, $db_user);
$mysqli = mysqli_connect($db_host, $db_user, $db_name);
if ($mysqli == FALSE)
die ("Errore nella connessione.");
// imposto charset utf8
if (!mysqli_set_charset($mysqli, 'utf8')) {
die ("Error: Unable to set the character set.\n");
exit;
}
//$res = mysql_select_db($db_name);
$res = mysqli_select_db($mysqli, $db_name);
if ($res == FALSE)
die ("Errore nella selezione del DB.");
// query per vedere se c'è già un commento uguale
//$query="SELECT * FROM guestbook WHERE Email='$aaemail' AND Comments='$commento'";
//$result = mysql_query($query);
//$result = mysqli_query($mysqli,"SELECT * FROM guestbook WHERE Email='$aaemail' AND Comments='$commento'");
$stmt = $mysqli->prepare("SELECT * FROM guestbook WHERE Email=? AND Comments=?");
$stmt->bind_param("ss", $aaemail, $commento);
//$result = $stmt->execute();
$result = $stmt->execute() ? $stmt->get_result() : false;
//$numero = mysql_num_rows($result);
$stmt->close();
if($result) {$numero = mysqli_num_rows($result);}else {$numero = 0;}
//$stmt->close();
if ($numero>0){
// messaggio di errore
?>
<br> <img src='imm/stop.gif'><br>...
<?php
}
//else
//$query="SELECT * FROM guestbook";
//$risultati=mysql_query($query);
$risultati=mysqli_query($mysqli,"SELECT * FROM guestbook");
$num=mysqli_num_rows($risultati);
$i=0;
$valmax=0;
while ($i < $num) {
//$valore=mysql_result($risultati,$i,"Id");
$valore=mysqli_result($risultati,$i,"Id");
if ($valore>$valmax) {
$valmax=$valore;
}
$i++;
}
$ultimo=$valmax+1;
//$ultimo=mysql_numrows($risultati)+1; // non commntato da GraphOGLRisorse
// aggiungo record
// $query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('$ultimo','$nome', '$aaemail', '$commento', '$localita', '$tempo', '$indirizzoip')";
// $query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('".$ultimo."','".$nome."', '".$aaemail."', '".$commento."', '".$localita."', '".$tempo."', '".$indirizzoip."')";
$query="INSERT IGNORE INTO guestbook(Id, Name, Email, Comments, Location, DateSent, IPAddress) VALUES(?, ?, ?, ?, ?, ?, ?)";
$stmt2 = $mysqli->prepare($query);
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
//$result = mysql_query($query);
//$result = mysqli_query($mysqli, $query);
// controllo l'esito
if (!$result) {
//die("Errore nella query $query: " . mysql_error());
die("Errore nella query $query: " . mysqli_error($mysqli));
}
// chiudo la connessione a MySQLi
//mysql_close();
mysqli_close($mysqli);
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt->affected_rows2."<br />";
echo "Ultimo ID inserito: ".$stmt->insert_id2 ."<br />";
}
}
?>
<p align="center"><font face="arial, Helvetica, sans-serif" size="4" color="#3366FF"><B>Grazie per aver firmato il Libro</B>...
<?php
}
}
}
}
}
?>
<?php
// dati di connessione al prprio database MySQL
$db_host = 'localhost';
$db_user = 'xxxxxx';
$db_name = 'my_xxxxxx';
// connessione al DB utilizzando MySQLi
$mysqli = new mysqli($db_host, $db_user, null, $db_name);
// verifica di eventuali errori della connessione
if ($mysqli->connect_errno) {
die ("Connessione fallita: ". $mysqli->connect_error . ".");
exit();
}
$result = $mysqli->query("SELECT * FROM guestbook");
echo "<table><tr>";
echo "<th>ID</th><th>Nome </th><th>email </th><th>commento </th><th>localita </th><th>tempo </th><th>indirizzoip</th>";
echo "</tr>";
while($riga=$result->fetch_assoc()){
?>
<!--<th><?php printf($riga['Id']);?></th>-->
<th><?php printf($riga['Name']);?></th>
<th><?php printf($riga['Email']);?></th>
<th><?php printf($riga['Comments']);?></th>
<th><?php printf($riga['Location']);?></th>
<th><?php printf($riga['DateSent']);?></th>
<th><?php printf($riga['IPAddress']);?></th><br>
<?php
}
echo "</table>";
// chiusura della connessione
$mysqli->close();
?>
cordiali saluti
-
Il 2 va anche nelle righe echo, dato che la query record ha come variabile $stmt2, era uesto che intendevo:
Codice PHP:
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
Cordiali saluti.
-
Grazie, non avevo capito.
Ho corretto, nessun errore, ma NON inserisce lo stesso il messaggio nella tabella Guestbook.
Fa tutto come se l'avesse inserito ma niente. Come mai?
Cordiali saluti
-
Provi con queste modfiche:
Codice PHP:
<?php
error_reporting
$db_host = "localhost";
$db_user = "pinco";
$db_name = "my_pinco";
//$db = mysql_connect($db_host, $db_user);
$mysqli = new mysqli($db_host, $db_user, null, $db_name);
if ($mysqli->connect_errno){
die ("Errore nella connessione.".$mysqli->connect_error);
exit;
}
// imposto charset utf8
if (!mysqli_set_charset($mysqli, 'utf8')) {
die ("Error: Unable to set the character set.\n");
exit;
}
//$res = mysql_select_db($db_name);
$res = $mysqli->select_db($db_name);
if ($res == FALSE)
die ("Errore nella selezione del DB.");
// query per vedere se c'è già un commento uguale
//$query="SELECT * FROM guestbook WHERE Email='$aaemail' AND Comments='$commento'";
//$result = mysql_query($query);
$stmt = $mysqli->prepare("SELECT * FROM guestbook WHERE Email=? AND Comments=?");
$stmt->bind_param("ss", $aaemail, $commento);
$result = $stmt->execute() ? $stmt->get_result() : false;
//$numero = mysql_num_rows($result);
//$numero = mysqli_num_rows($result);
//$stmt->close();
$stmt->close();
if($result) {$numero = $stmt->num_rows;}else {$numero = 0;}
//mysqli_store_result($mysqli);
//$result = $stmt->store_result();
if ($numero>0){
// messaggio di errore
?>
<br> <img src='imm/stop.gif'><br><font face='arial' color='#cc0000'><B> E che cavolo fai!!! Ripeti?<br> E cöse belin ti fæ!!! Torna?<br> What accident you do!!! Do you repeat?<br><br><A href='sign-form.php' title='Torna inderê - Go back'> << Ritorna indietro</A></B></font>
<?php
}
//else
//$query="SELECT * FROM guestbook";
//$risultati=mysql_query($query);
$risultati=$mysqli->query("SELECT * FROM guestbook");
//$num=mysql_numrows($risultati);
$num=$risultati->num_rows;
$i=0;
$valmax=0;
while ($i < $num) {
//$valore=mysql_result($risultati,$i,"Id");
$valore=mysqli_result($risultati,$i,"Id");
if ($valore>$valmax) {
$valmax=$valore;
}
$i++;
}
$ultimo=$valmax+1;
//$ultimo=mysql_numrows($risultati)+1; // non commntato da GraphOGLRisorse
// aggiungo record
$query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('?, ?, ?, ?, ?, ?, ?')";
//$result = mysql_query($query);
$stmt2 = $mysqli->prepare($query);
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
$stmt2->close();
// controllo l'esito
if (!$result) {
//die("Errore nella query $query: " . mysql_error());
die("Errore nella query '".$query."': " . $stmt2->error);
}
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
// chiudo la connessione a MySQLi
//mysql_close();
$mysqli->close();
?>
<p align="center"><font face="arial, Helvetica, sans-serif" size="4" color="#3366FF"><B>Grazie per aver firmato il Libro</B>
<br>Graçie pe avéi firmòu o Libbro<br>Thank you for signing the Guest-Book.</font></p>
<p align="center"> </p>
<?php
}
}
}
}
}
?>
Cordiali saluti.
-
Ho provato con queste modifiche e mi dà:
Parse error: syntax error, unexpected '$db_host' (T_VARIABLE) in /membri/paolin/sign-invio-prova.php on line 149
Poi ho provato a correggere error_reporting con error_reporting(E_ALL); e ora mi dà:
Warning: main(): Couldn't fetch mysqli_stmt in /membri/paolin/sign-invio-prova.php on line 183
Fatal error: Call to a member function bind_param() on boolean in /membri/paolin/sign-invio-prova.php on line 220
Alla line 183 c'è
Codice PHP:
if($result) {$numero = $stmt->num_rows;}else {$numero = 0;}
mentre alla line 220 c'è:
Codice PHP:
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
Cordiali saluti
-
Si, error_reporting(E_ALL) è giusto come l'ha corretto, non mi ero accorto che avevo omesso una parte.
Per la linea 183;
Codice PHP:
if($result) {$numero = $result->num_rows;}else {$numero = 0;}
$stmt->close();
Per la linea 220;
Codice PHP:
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
}else {
var_dump($mysqli->error);
}
-
Ho modificato e ora mi dà:
string(47) "Column count doesn't match value count at row 1"
Notice: Trying to get property of non-object in /membri/paolin/sign-invio-prova.php on line 236
Grazie per aver firmato il Libro...
Alla linea 236 c'è
if($stmt2->num_rows > 0) {
Codice PHP:
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
La Tabella ha 7 colonne: ID, Name, Email, Comments, Location, Date Sent, IPAdress
Cordiali saluti
-
Sposti tutto blocco prima di $stmt2->close() come riportato qui:
Codice PHP:
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
$stmt2->close();
Cordiali saluti.
-
Ho fatto come mi ha detto, ma purtroppo mi dà:
string(47) "Column count doesn't match value count at row 1"
Notice: Trying to get property of non-object in /membri/paolin/sign-invio-prova.php on line 229
Fatal error: Call to a member function close() on boolean in /membri/paolin/sign-invio-prova.php on line 235]
dove alla linea 229 c'è
Codice PHP:
if($stmt2->num_rows > 0) {
e alla linea 235 c'è
Codice PHP:
$stmt2->close();
Togliendo la linea 235 mi dà solo:
string(47) "Column count doesn't match value count at row 1"
Notice: Trying to get property of non-object in /membri/paolin/sign-invio-prova.php on line 229
Grazie per aver firmato il Libro ...
Ecco il codice intero
Codice PHP:
<?php
}
//else
//$query="SELECT * FROM guestbook";
//$risultati=mysql_query($query);
$risultati=$mysqli->query("SELECT * FROM guestbook");
//$num=mysql_numrows($risultati);
$num=$risultati->num_rows;
$i=0;
$valmax=0;
while ($i < $num) {
//$valore=mysql_result($risultati,$i,"Id");
$valore=mysqli_result($risultati,$i,"Id");
if ($valore>$valmax) {
$valmax=$valore;
}
$i++;
}
$ultimo=$valmax+1;
//$ultimo=mysql_numrows($risultati)+1; // non commntato da GraphOGLRisorse
// aggiungo record
$query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('?, ?, ?, ?, ?, ?, ?')";
//$result = mysql_query($query);
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
}
else {
var_dump($mysqli->error);
}
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
$stmt2->close();
// controllo l'esito
if (!$result) {
//die("Errore nella query $query: " . mysql_error());
die("Errore nella query '".$query."': " . $stmt2->error);
}
// chiudo la connessione a MySQLi
//mysql_close();
$mysqli->close();
?>
<p align="center"><font face="arial, Helvetica, sans-serif" size="4" color="#3366FF"><B>Grazie per aver firmato il Libro</B>
</font></p>
<p align="center"> </p>
<?php
}
}
}
}
}
?>
cordiali saluti
-
Provi prima così:
Codice PHP:
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
$stmt2->store_result();
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
$stmt2->close();
}
else {
var_dump($mysqli->error);
}
Se ci sono ancora errori con:
Codice PHP:
// verifica funzionamento
if($result){
if($stmt2->num_rows > 0) {
echo "Righe generate: ".$stmt2->affected_rows."<br />";
echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
}
}
Commenti il blocco di verifica qui sopra, è solo per verifcare l'output ma non è necessarioa al fine funzionale.
Cordiaali saluti.
-
Mi dà :
string(47) "Column count doesn't match value count at row 1"
Fatal error: Call to a member function close() on boolean in /membri/paolin/sign-invio-prova.php on line 240
line 240
Codice PHP:
$stmt2->close();
il codice che ho usato è questo
Codice PHP:
<?php
}
//else
//$query="SELECT * FROM guestbook";
//$risultati=mysql_query($query);
$risultati=$mysqli->query("SELECT * FROM guestbook");
//$num=mysql_numrows($risultati);
$num=$risultati->num_rows;
$i=0;
$valmax=0;
while ($i < $num) {
//$valore=mysql_result($risultati,$i,"Id");
$valore=mysqli_result($risultati,$i,"Id");
if ($valore>$valmax) {
$valmax=$valore;
}
$i++;
}
$ultimo=$valmax+1;
//$ultimo=mysql_numrows($risultati)+1; // non commntato da GraphOGLRisorse
// aggiungo record
$query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('?, ?, ?, ?, ?, ?, ?')";
//$result = mysql_query($query);
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
$stmt2->store_result();
// verifica funzionamento
//if($result){
//if($stmt2->num_rows > 0) {
//echo "Righe generate: ".$stmt2->affected_rows."<br />";
//echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
//}
//}
$stmt2->close();
}
else {
var_dump($mysqli->error);
}
$stmt2->close();
// controllo l'esito
if (!$result) {
//die("Errore nella query $query: " . mysql_error());
die("Errore nella query '".$query."': " . $stmt2->error);
}
// chiudo la connessione a MySQLi
//mysql_close();
$mysqli->close();
?>
Mi sembra che non riusciamo a farlo funzionare... forse è meglio che lascio il documento con mysql (sebbene deprecato) finché sarà supportato...
La ringrazio.
Cordiali saluti
-
Cancelli il secondo $stmt2->close(), quello dopo var_dump($mysqli->error);
Cordiali saluti.
-
string(47) "Column count doesn't match value count at row 1"
Grazie per aver firmato il Libro...
E NON inserisce nulla.
Cordiali saluti
-
L'erroere indica che c'è la richiesta di inserire una riga con un certo numero di colonne, ma che il numero fornito di colonne è differente.
Riguardando gli utltimi messaggi, mi è venuto il dubbio che abbia nel codice un secondo error_reporting(E_ALL).
In tal caso tolga il secondo.
Cordiali saluti.
-
Ha ragione, ce n'erano due: uno all'inizio prima di "§session_start()",
e uno alla linea 147 prima di
Codice PHP:
$db_host = 'localhost';
$db_user =...
$mysqli = new mysqli($db_host, $db_user, null, $db_name);
Ho tolto il secondo, ma il risultato non cambia!
string(47) "Column count doesn't match value count at row 1"
Grazie per aver firmato il Libro
Cordiali saluti
-
Potrebbe esere generato da problemi con alcuni post che non ricevono gli elementi.
Agguiunga questo codice come semplice debug:
Codice PHP:
echo "<pre>";
var_dump($_POST);
echo "<pre>"
Cordiali saluti.
-
Scusi, in che punto devo inserirlo?
Grazie.
-
Dopo la procedura della query record (qella con INSERT).
Cordiali saluti.
-
Mi dice:
Parse error: syntax error, unexpected '$stmt2' (T_VARIABLE), expecting ',' or ';' in /membri/paolin/sign-invio-prova.php on line 236
line 236 c'è
Codice PHP:
$stmt2->close();
Il codice debug l'ho messo dopo INSERT IGNORE...
Codice PHP:
$query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('?, ?, ?, ?, ?, ?, ?')";
//$result = mysql_query($query);
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
$stmt2->store_result();
echo "<pre>";
var_dump($_POST);
echo "<pre>"
// verifica funzionamento
//if($result){
//if($stmt2->num_rows > 0) {
//echo "Righe generate: ".$stmt2->affected_rows."<br />";
//echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
//}
//}
$stmt2->close();
}
else {
var_dump($mysqli->error);
}
Cordiali saluti
-
Manca un punto e virgila dopo il secindo echo "<pre>"
Cordiali saluti.
-
Messo ;
siamo da capo:
string(47) "Column count doesn't match value count at row 1"
Grazie per aver firmato il Libro...
Cordiali saluti
-
Lo sposti dopo esle, dentro le parentesi prima di var_dump($mysqli->error);
Cordiali saluti.
-
ho fatto come mi ha detto, così:
Codice PHP:
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param("issssss", $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
$result = $stmt2->execute();
$stmt2->store_result();
// verifica funzionamento
//if($result){
//if($stmt2->num_rows > 0) {
//echo "Righe generate: ".$stmt2->affected_rows."<br />";
//echo "Ultimo ID inserito: ".$stmt2->insert_id ."<br />";
//}
//}
$stmt2->close();
}
else {
echo "<pre>";
var_dump($_POST);
echo "<pre>";
var_dump($mysqli->error);
}
e ora mi dice:
array(6) {
["fullname"]=>
string(7) " lilla7"
["email"]=>
string(17) "prova77@libero.it"
["comments"]=>
string(6) "provaa"
["location"]=>
string(1) " "
["anti_spam_code"]=>
string(6) "481103"
["Submit"]=>
string(5) "Invia"
}
string(47) "Column count doesn't match value count at row 1"
Grazie per aver firmato il Libro
...
Cordiali saluti
-
Si, era questo che volevo vedere.
Ho notato che "location" equivale a "". L'ha omesso lei il dato quando ha eseguito la prova?
Se sì, allora i post sembrano essere tutti a posto.
Quel messaggio di errore vine visualizzato da var_dump($mysqli->error) e probabilmente è il motivo percui in precedenza, qunado non dava apparentemente errore si bloccava e non scriveva nel database.
Controlli eventualmente se manca qualche apice (l'apostrofo) da qualche parte.
Dopo $stmt2->bind_param() e prima di $stmt2->execute(), inserisca quanto segue:
Codice PHP:
while($stmt2->fetch()) {
print $nome.' '.$aaemail.' '.$commento.' '.$localita.' '.$tempo.' '.$indirizzoip;
}
Cordiali saluti.
-
Grazie per la risposta dettagliata.
Il campo Location l'avevo omesso io volutamente.
Ho controllato l'eventuale mancanza di apice ma io non ho trovato nulla.
Ho inserito il codice dove mi ha detto, ma mi dà la stessa cosa:
array(6) {
["fullname"]=>
string(8) " lilla80"
["email"]=>
string(18) "prova777@libero.it"
["comments"]=>
string(7) "provaaa"
["location"]=>
string(3) " bo"
["anti_spam_code"]=>
string(6) "128510"
["Submit"]=>
string(5) "Invia"
}
string(47) "Column count doesn't match value count at row 1"
Grazie per aver firmato il Libro
...
Cordiali saluti
-
Non riesco a risolvere questo problema "Column count doesn't match value count at row 1"
Ho cercato in rete, ho letto su vari forum (https://stackoverrun.com/it/q/1471813 o https://stackoverflow.com/questions/...count-at-row-1)
in alcuni dicono che se ID si autoincrementa non è necessario inserirlo... nel vecchio codice Mysql c'era.
GraphOGLRisorse è stato finora gentilissimo nell'aiutarmi, ma siamo ad un vicolo cieco: :confused:
il codice non da errori, tranne "Column count doesn't match value count at row 1", e non inserisce nulla nella tabella;
il codice è
Codice PHP:
$risultati=$mysqli->query("SELECT * FROM guestbook");
//$num=mysql_numrows($risultati);
$num=$risultati->num_rows;
$i=0;
$valmax=0;
while ($i < $num) {
//$valore=mysql_result($risultati,$i,"Id");
$valore=mysqli_result($risultati,$i,"Id");
if ($valore>$valmax) {
$valmax=$valore;
}
$i++;
}
$ultimo=$valmax+1;
//$ultimo=mysql_numrows($risultati)+1; // non commntato da GraphOGLRisorse
// aggiungo record
$query="INSERT IGNORE INTO guestbook (Id, Name, Email, Comments, Location, DateSent, IPAddress ) VALUES ('?, ?, ?, ?, ?, ?, ?')";
//$result = mysql_query($query);
if($stmt2 = $mysqli->prepare($query)) {
$stmt2->bind_param('issssss', $ultimo, $nome, $aaemail, $commento, $localita, $tempo, $indirizzoip);
while($stmt2->fetch()) {
print $ultimo.' '.$nome.' '.$aaemail.' '.$commento.' '.$localita.' '.$tempo.' '.$indirizzoip;
}
$result = $stmt2->execute();
$stmt2->store_result();
Se serve posto l'intera pagina.
Grazie a chiunque potrà aiutarmi
-
In $stmt2->bind_param, provi a sostituire $ultimo con $valmax.
Coridali saluti.
-
Grazie, ma purtroppo non cambia nulla e non inserisce nulla.
Stesso risultato del post #115
Ho provato anche ad eliminare "IGNORE" da "INSERT IGNORE INTO guestbook" ma non cambia nulla!
Non so più cosa fare :confused:
Non sarà che con mysqli va cambiata qualche impostazione nel campo ID della tabella?
Cordiali saluti