query semplice?

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Ciao a tutti,
dopo essermi allontanato dai pc in generale per mesi... ora per lavoro, dovrei risolvere un problemino che vi pongo.

Ho questa query:
PHP:
$result = mysql_query("SELECT * FROM fatture WHERE doc = 'FATTURA' && indice = '$txt' order by id desc");

Che chiede di elencare i record della tabella "fatture" ma solo quelli che hanno nel campo "doc" la scritta "FATTURA" e nel campo "indice" la scritta che voglio io...

Vorrei che mi elencasse anche quelli che nel campo "doc", oltre alla scritta "FATTURE", abbiano la scritta "NOTA DI CREDITO" e sempre nel campo "indice" la scritta che voglio io...

Ho provato così, ma non va:
PHP:
$result = mysql_query("SELECT * FROM fatture WHERE doc = 'FATTURA' && doc = 'NOTA DI CREDITO' && indice = '$txt' order by id desc");
 

f107

Utente Attivo
7 Ago 2012
206
6
18
Roma
Prova cosi
PHP:
"SELECT * FROM fatture WHERE (doc = 'FATTURA' || doc = 'NOTA DI CREDITO' ) && indice = '$txt' order by id desc"
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
un altro quesito...
Ho questa pagina,

PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;
else{ 
header("Location: login.htm");
}

 { ?><html>
<head>
<title>DDT</title>
</head>
<td align='left'><font size='2'><form align='' action='ddt.php?reg=1' method='POST'>Inserisci l'indice<input type='text' name='txt'>
<input style='color:black;background-color:;' type='submit' value='Cerca'>
</form></font></td>

<?php 
$DB_host     = 'localhost';
$DB_user     = 'XXXXXX';
$DB_password = 'password';
$DB_name     = 'name';
$b=date('ymd');
$bi=date('d/m/y');
$link = mysql_connect($DB_host, $DB_user, $DB_password);
if (!$link) {
	die ('Non riesco a connettermi: ' . mysql_error());
}
$db_selected = mysql_select_db($DB_name, $link);
if (!$db_selected) {
	die ("Errore nella selezione del database: " . mysql_error());
}
$txt = $_POST['txt'];

echo "<td align='left'><p align='left'><font color='black' size='4'>
<b>Elenco DDT $bi</b><a title='STAMPA' href='javascript:print();'>
<input style='color:black;background-color:;' type='submit' value='Stampa'></a></font></p><td>";

<!------------------qui vorrei aggiungere il tastino invia---->

$result = mysql_query("SELECT * FROM documenti WHERE doc LIKE 'DDT' && indice = '$txt' order by id desc");
$num=mysql_numrows($result);
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr> 

<th align='center' width=''><font size='2'>Ragione sociale</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Importo</th>
<th align='center' width=''><font size='2'>Tipo</th>
</tr>"; 
$totale_importo = 0;
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center'><font size='2'>".$row['tipo']."</font></td>
</tr>";
     
     $importo=mysql_result($result,$i,"importo");
    $totale_importo += $importo;
    $i++;  
}  
echo "</table><br>";
?>
<table style='border: 1px solid white' align='left' bgcolor='' border='0' width='100%' cellpadding='0' cellspacing='10'>
<td align="center"><font size='2'>Totale importo: <b><?php echo $totale_importo ?>&nbsp;</b>euro</font></td>
</table>

 </html><? } ?>
Avrei bisogno di inserire un tastino "invia tramite e-mail" e inviare i dati tramite il mio programma di posta oppure via modulo diretto (che sarebbe ancora meglio!)

ho trovato una cosa del genere ma non so come applicarlo.... :-(
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Allora, ho avanzato nel progetto "pagina con tasto invio"
ho creato una pagina che ho chiamato invio.php che è così:
PHP:
<?php
//varie info per email
$oggi = date("j F Y G:i");
$sito = "XXXXX";
$ip = "$_SERVER[REMOTE_ADDR]";
$browser = "$_SERVER[HTTP_USER_AGENT]";
$to = "XXX@XXX";
$soggetto = "DDT da Fatturare";

if(trim($_POST['nome']) == "" OR trim($_POST['doc']) == "" OR trim($_POST['numero']) == "" OR trim($_POST['emissione']) == "" OR trim($_POST['codcliente']) == "" OR trim($_POST['importoDDT']) == "" OR trim($_POST['data']) == "" OR trim($_POST['tipo']) == "") {
echo "<font color=\"black\" size=\"2\"><strong>Attenzione! Tutti i campi sono obbligatori!</strong></font>";

} else {

$body = "Modulo inviato il $oggi da $ip - $browser \n\n";
$body .= "Nome: $_POST[nome] \nDocumento: $_POST[doc] \nNumero: $_POST[numero]\nEmissione: $_POST[emissione]\nCodicecliente: $_POST[codcliente]\nImportoDDT: $_POST[importoDDT]\nData: $_POST[data]\nTipo: $_POST[tipo]";

mail("$to","$soggetto","$body");
?>
<html>
<head>
<title>Annuncio inviato</title>
</head>
<body background="white" style="background-attachment: fixed; text-align:center" link="black" vlink="black" alink="black" text="black">
<div align="center"><BR><br>
<font size="+1" face=""><strong>Il modulo è stato inviato con successo!<br><br> Grazie.
</strong></font>

</div>
</body>
</html>
<?php
}
?>





e il modulo è questo:
PHP:
<head>
<title>DDT</title>
<!----------------- inizio script modulo ---------------------------->
<script language="javascript" type="text/javascript">
<!--
function Modulo() {

if ((document.modulo.nome.value == "")) {
alert("Il campo Nome è obbligatorio");
document.modulo.nome.focus();
return false;
}

else if ((document.modulo.doc.value == "")) {
alert("Il campo Doc è vuoto. Se non lo vuoi fornire, digita il segno -");
document.modulo.doc.focus();
return false;
}

else if ((document.modulo.numero.value == "")) {
alert("Il campo numero è vuoto. Se non la vuoi fornire, digita il segno -");
document.modulo.numero.focus();
return false;
}

else if ((document.modulo.emissione.value == "")) {
alert("Il campo Emissione di provenienza è obbligatorio");
document.modulo.emissione.focus();
return false;
}


else if ((document.modulo.codcliente.value == "")) {
alert("Il campo codcliente è obbligatorio");
document.modulo.codcliente.focus();
return false;
}

else if ((document.modulo.importoDDT.value == "")) {
alert("Il campo importoDDT è obbligatorio");
document.modulo.importoDDT.focus();
return false;
}

else if ((document.modulo.data.value == "")) {
alert("Il campo data è obbligatorio");
document.modulo.data.focus();
return false;
}

else if ((document.modulo.tipo.value == "")) {
alert("Il campo tipo è obbligatorio");
document.modulo.tipo.focus();
return false;
}

else {
document.modulo.action = "invio.php";
document.modulo.submit();
}
}
//-->
</script>
<!----------------- fine script modulo ---------------------------->

</head>
<td align='left'><font size='2'><form align='' action='ddt.php?reg=1' method='POST'>Inserisci l'indice<input type='text' name='txt' value='<?php echo $oggi ?>'>
<input style='color:black;background-color:;' type='submit' value='Cerca'>
</form></font></td>
<?php 
$DB_host     = 'localhost';
$DB_user     = 'XXXX';
$DB_password = 'XXXXX';
$DB_name     = 'XXXXX';
$b=date('ymd');
$bi=date('d/m/y');
$link = mysql_connect($DB_host, $DB_user, $DB_password);
if (!$link) {
	die ('Non riesco a connettermi: ' . mysql_error());
}
$db_selected = mysql_select_db($DB_name, $link);
if (!$db_selected) {
	die ("Errore nella selezione del database: " . mysql_error());
}
$txt = $_POST['txt'];

echo "<td align='left'><p align='left'><font color='black' size='4'>
<b>Elenco DDT $bi</b><a title='STAMPA' href='javascript:print();'>
<input style='color:black;background-color:;' type='submit' value='Stampa'></a></font></p><td>";

$result = mysql_query("SELECT * FROM XXXXXX WHERE doc LIKE 'DDT' && indice = '$txt' order by id desc");
$num=mysql_numrows($result);
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr> 

<th align='center' width=''><font size='2'>Ragione sociale</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo DDT</th>
<th align='center' width=''><font size='2'>Data</th>
<th align='center' width=''><font size='2'>Tipo</th>

</tr>"; 
$totale_importo = 0;
echo "<form method='POST' name='modulo' action='invio.php'  target='_blank'>";
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];  

    echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome' maxlength='30' value='".$row['nome']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='doc' maxlength='30' value='".$row['doc']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='numero' maxlength='30' value='".$row['numero']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='emissione' maxlength='30' value='".$row['emissione']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='codcliente' maxlength='30' value='".$row['codcliente']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='importoDDT' maxlength='30' value='".$row['importoDDT']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='data' maxlength='30' value='".$row['data']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='tipo' maxlength='30' value='".$row['tipo']."'></font></td>

</tr>";

     
    $importoDDT=mysql_result($result,$i,"importoDDT");
    $totale_importo += $importoDDT;
    $i++;  
}  
echo "<td> <input type='button' value='Invia' onClick='Modulo()'></td>";
echo "</form>";
echo "</table><br>";
?>

<table style='border: 1px solid white' align='left' bgcolor='' border='0' width='100%' cellpadding='0' cellspacing='10'>
<td align="center"><font size='2'>Totale importo: <b><?php echo $totale_importo ?>&nbsp;</b>euro</font></td>
</table>
 </html><? } ?>

Funzionerebbe, ma invia solo l'ultimo record che trova il db... io vorrei inviare tutti i record!!!!
Come si faaaa????
Grazie...
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
il problema che i invia solo l'ultimo è dovuto al fatto che tu hai un ciclo while (semplifico)
PHP:
<?php
//...
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
	echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome' maxlength='30' value='".$row['nome']."'></font></td> ecc.."
}
//...
?>
il campo di input name='nome' e quindi il relativo $_POST['nome'] assume come valore l'ultimo $row['nome']
devi rendere il campo di input con un nome array
PHP:
<?php
//...
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
	echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome[]' maxlength='30' value='".$row['nome']."'></font></td> ecc.."
}
//...
?>
poi nel invio.php devi estrarre l'array (es)
in $_POST['nome'][0] trovi PINCO
e
in $_POST['nome'][1] trovi PALLINO
analogamente per tutti glia altri compi di input ripetuti
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Stasera appena torno a casa, provo subito. Anche se credo di aver bisogno di un esempio pratico.. Be, vedremo... Per ora grazie!
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
No, non ci ho capito... ora non mi invia più nemmeno il form... :-(
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
perche il js non sta controllando un array.
abbandona js e fai i controlli via php, tra l'altro sono molto più sicuri


p.s.
guarda inoltre, a che ne so, non è corretto fare (schematizzo)
<table>
<form>
</form>
</table>
la maniera corretta è
<form>
<table>
</table>
</form>
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
ma se nel "name" inserisco il risutato del row... così...
PHP:
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
   

    echo "<tr>
     <td align='center'><font size='2'><input type='text' name='".$row['nome']."' maxlength='30' value='".$row['nome']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['doc']."' maxlength='30' value='".$row['doc']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['numero']."' maxlength='30' value='".$row['numero']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['emissione']."' maxlength='30' value='".$row['emissione']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['codcliente']."' maxlength='30' value='".$row['codcliente']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['importoDDT']."' maxlength='30' value='".$row['importoDDT']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['data']."' maxlength='30' value='".$row['data']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='".$row['tipo']."' maxlength='30' value='".$row['tipo']."'></font></td>
     


</tr>";

e nella pagina "invio.php"

modifico così...
PHP:
if(trim($_POST['".$row['nome']."']) == "" OR trim($_POST['".$row['doc']."']) == "" OR trim($_POST['".$row['numero']."']) == "" OR trim($_POST['".$row['emissione']."']) == "" OR trim($_POST['".$row['codcliente']."']) == "" OR trim($_POST['".$row['importoDDT']."']) == "" OR trim($_POST['".$row['data']."']) == "" OR trim($_POST['".$row['tipo']."']) == "") {
echo "<font color=\"black\" size=\"4\"><strong>Attenzione! Tutti i campi sono obbligatori!</strong></font>";

} else {

$body = "Modulo inviato il $oggi da $ip - $browser \n\n";
$body .= "Nome: $_POST['".$row['nome']."'] \nDocumento: $_POST['".$row['doc']."'] \nNumero: $_POST['".$row['numero']."'] \nEmissione: $_POST['".$row['emissione']."'] \nCodicecliente: $_POST['".$row['codcliente']."'] \nImportoDDT: $_POST['".$row['importoDDT'']."] \nData: $_POST['".$row['data']."'] \nTipo: $_POST['".$row['tipo']."']";


non è teoricamente giusto?
Comunque non va nemmeno così...
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
cosa intendi con "non mi va";
nel codice che dicevi che ti inviava solo l'ultimo correggi
PHP:
<?php
//.....
$totale_importo = 0;
echo "<form method='POST' name='modulo' action='invio.php'  target='_blank'>";
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr> 
<th align='center' width=''><font size='2'>Ragione sociale</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo DDT</th>
<th align='center' width=''><font size='2'>Data</th>
<th align='center' width=''><font size='2'>Tipo</th>
</tr>"; 
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];  
    echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome[]' maxlength='30' value='".$row['nome']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='doc[]' maxlength='30' value='".$row['doc']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='numero[]' maxlength='30' value='".$row['numero']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='emissione[]' maxlength='30' value='".$row['emissione']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='codcliente[]' maxlength='30' value='".$row['codcliente']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='importoDDT[]' maxlength='30' value='".$row['importoDDT']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='data[]' maxlength='30' value='".$row['data']."'></font></td>
     <td align='center'><font size='2'><input type='text' name='tipo[]' maxlength='30' value='".$row['tipo']."'></font></td>

</tr>";
    //?
	$importoDDT=mysql_result($result,$i,"importoDDT");
    $totale_importo += $importoDDT;
	/*
	non potresti semplicemente fare
	$totale_importo += $row['importoDDT'];
	visto che gia la usi
	*/
    $i++;  
} 
echo "<tr><td> <input type='button' value='Invia'></td></tr>";//qui mancano un po' di td
echo "</table><br>";
echo "</form>";
?>

anche se secondo me sarebbe da riguardare un po' tutto es vedeo che hai due form in cui col primo inputi la data per estrre i record
ma se non metti l'i isset submit appena apri la pagina la query (se non vedo male) ti sballa, la query andrebbe eseguita solo dopo che hai impostato la ricerca
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
ciao
il problema che i invia solo l'ultimo è dovuto al fatto che tu hai un ciclo while (semplifico)
PHP:
<?php
//...
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
	echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome' maxlength='30' value='".$row['nome']."'></font></td> ecc.."
}
//...
?>
il campo di input name='nome' e quindi il relativo $_POST['nome'] assume come valore l'ultimo $row['nome']
devi rendere il campo di input con un nome array
PHP:
<?php
//...
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
	echo "<tr>
     <td align='center'><font size='2'><input type='text' name='nome[]' maxlength='30' value='".$row['nome']."'></font></td> ecc.."
}
//...
?>
poi nel invio.php devi estrarre l'array (es)
in $_POST['nome'][0] trovi PINCO
e
in $_POST['nome'][1] trovi PALLINO
analogamente per tutti glia altri compi di input ripetuti

Ma come faccio nella pagina "invio.php" a estrarre l'array? Io non posso sapere quanti record mi darà la pagina...
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
prova così (schematizzo)
PHP:
<?php
//.....
$errore="";
for($j=0; $j < count($_POST['nome']; $j++){
	if(trim($_POST['nome'][$j]) ==""){$errore.="il campo nome ".($j+1)." obbligatorio<br>";}
	if(trim($_POST['doc'][$j]) ==""){$errore.="il campo documento ".($j+1)." obbligatorio<br>";}
	//ecc... per tutti i campi
}
if($errore==""){
	$totale=0;
	$messaggio= "<table>";
	$messaggio .= "<tr> 
			<th align='center' width=''><font size='2'>Ragione sociale</th>
			<th align='center' width=''><font size='2'>Documento</th>
			<th align='center' width=''><font size='2'>Numero</th>
			<th align='center' width=''><font size='2'>Emissione</th>
			<th align='center' width=''><font size='2'>Codice cliente</th>
			<th align='center' width=''><font size='2'>Importo DDT</th>
			<th align='center' width=''><font size='2'>Data</th>
			<th align='center' width=''><font size='2'>Tipo</th>
			</tr>";
	for($j=0; $j < count($_POST['nome']; $j++){
		$messaggio .= "<tr>";
		$messaggio .= "<td>".$_POST['nome'][$j]."</td><td>".$_POST['doc'][$j]."</td> ...eccetera......</td>";
		$totale +=$_POST['importoDDT'][$j]
	}
	$messaggio .= "</tr>";
	$messaggio .= "<tr><td colspan=\"6\">&nbsp;</td><td>TOTALE</td><td>$totale</td></tr>";//il numero dei <td>..</td> deve essere come ha impostato la tabella o usare colspan
	$messaggio .="</table>";
	//e qui lo stampi o fai quello che vuoi
	echo $messaggio;
}else{
	echo $errore;
	//e riinvii dove vuoi
}
//...
?>
se devi inviarlo per email usa phpmailer non la funzione mail()
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Niente, ci ho provato ma sono duro come le pine verdi...
Mi potresti modificare questa pagina anche solo con due campi...?
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;
else{ 
header("Location: login.htm");
}
$oggi=date('yW');
 { ?><html>
<head>
<title>DDT</title>
<!----------------- inizio script modulo ---------------------------->
<script language="javascript" type="text/javascript">
<!--
function Modulo() {
if ((document.modulo.nome.value == "")) {
alert("Il campo Nome è obbligatorio");
document.modulo.nome.focus();
return false;
}

else if ((document.modulo.doc.value == "")) {
alert("Il campo Doc è vuoto. Se non lo vuoi fornire, digita il segno -");
document.modulo.doc.focus();
return false;
}

else if ((document.modulo.numero.value == "")) {
alert("Il campo numero è vuoto. Se non la vuoi fornire, digita il segno -");
document.modulo.numero.focus();
return false;
}

else if ((document.modulo.emissione.value == "")) {
alert("Il campo Emissione di provenienza è obbligatorio");
document.modulo.emissione.focus();
return false;
}


else if ((document.modulo.codcliente.value == "")) {
alert("Il campo codcliente è obbligatorio");
document.modulo.codcliente.focus();
return false;
}

else if ((document.modulo.importoDDT.value == "")) {
alert("Il campo importoDDT è obbligatorio");
document.modulo.importoDDT.focus();
return false;
}

else if ((document.modulo.data.value == "")) {
alert("Il campo data è obbligatorio");
document.modulo.data.focus();
return false;
}

else if ((document.modulo.tipo.value == "")) {
alert("Il campo tipo è obbligatorio");
document.modulo.tipo.focus();
return false;
}

else {
document.modulo.action = "invio.php";
document.modulo.submit();
}
}
//-->
</script>
<!----------------- fine script modulo ---------------------------->

</head>
<td align='left'><font size='2'><form align='' action='ddt.php?reg=1' method='POST'>Inserisci l'indice<input type='text' name='txt' value='<?php echo $oggi ?>'>
<input style='color:black;background-color:;' type='submit' value='Cerca'>
</form></font></td>
<?php 
$DB_host     = 'localhost';
$DB_user     = 'XXXXX';
$DB_password = 'XXXXX';
$DB_name     = 'XXXXXXX';
$b=date('ymd');
$bi=date('d/m/y');
$link = mysql_connect($DB_host, $DB_user, $DB_password);
if (!$link) {
	die ('Non riesco a connettermi: ' . mysql_error());
}
$db_selected = mysql_select_db($DB_name, $link);
if (!$db_selected) {
	die ("Errore nella selezione del database: " . mysql_error());
}
$txt = $_POST['txt'];

echo "<td align='left'><p align='left'><font color='black' size='4'>
<b>Elenco DDT $bi</b><a title='STAMPA' href='javascript:print();'>
<input style='color:black;background-color:;' type='submit' value='Stampa'></a></font></p><td>";

$result = mysql_query("SELECT * FROM fatture WHERE doc LIKE 'DDT' && indice = '$txt' order by id desc");
$num=mysql_numrows($result);
echo "<form method='POST' name='modulo' action='invio.php'  target='_blank'>";
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr> 

<th align='center' width=''><font size='2'>Ragione sociale</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo DDT</th>
<th align='center' width=''><font size='2'>Data</th>
<th align='center' width=''><font size='2'>Tipo</th>

</tr>"; 
$totale_importo = 0;

while($row = mysql_fetch_array( $result )) { 
    $id=$row['id']; 

    echo "<tr> 
     <td align='center'><font size='2'><input type='text' name='nome' maxlength='30' value='".$row['nome']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='doc' maxlength='30' value='".$row['doc']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='numero' maxlength='30' value='".$row['numero']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='emissione' maxlength='30' value='".$row['emissione']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='codcliente' maxlength='30' value='".$row['codcliente']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='importoDDT' maxlength='30' value='".$row['importoDDT']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='data' maxlength='30' value='".$row['data']."'></font></td> 
     <td align='center'><font size='2'><input type='text' name='tipo' maxlength='30' value='".$row['tipo']."'></font></td> 
      
</tr>";
     $totale_importo += $row['importoDDT'];  
    $i++;  
}  
echo "<td> <input type='button' value='Invia' onClick='Modulo()'></td>";
echo "</table><br>";
echo "</form>";
?>

<table style='border: 1px solid white' align='left' bgcolor='' border='0' width='100%' cellpadding='0' cellspacing='10'>
<td align="center"><font size='2'>Totale importo: <b><?php echo $totale_importo ?>&nbsp;</b>euro</font></td>
</table>

 </html><? } ?>

e anche senza verifica dei campi. Tanto lo uso solo io...
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
devo rifartela tutta, ma prima spiegami questa parte
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;//cosa è questo if e da dove sakta fuiri la variabile $usern?
else{ 
header("Location: login.htm");
}
$oggi=date('yW');
 { //????
?>
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
ciao
devo rifartela tutta, ma prima spiegami questa parte
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;//cosa è questo if e da dove sakta fuiri la variabile $usern?
else{ 
header("Location: login.htm");
}
$oggi=date('yW');
 { //????
?>

La variabile $usern la stabilisco io nella pagina "conf.php"... ;-)
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
l'ho un po' messa a posto, non so se funzia perchè non posso provarla.
guarda i commenti
PHP:
<?php
session_start();//sempre meglio metterla prima
include 'conf.php';
if ($_SESSION['username']==$usern);
else{ 
	header("Location: login.htm");
	exit();//metti l'exit per essere sicuro che durante il caricamento non possa essere letta
}
$oggi=date('yW');
//a che ti serve aprire e chiudere in fondo la {}
?>
<html>
<head>
<title>DDT</title>
</head>
<body><!-- e il  <body>...</body>-->
<!-- table e tr ?? -->
<font size='2'><!-- tag font deprecato usa i css -->
<form align='' action='ddt.php?reg=1' method='POST'>
<table><tr><td align='left'>
Inserisci l'indice <input type='text' name='txt' value='<?php echo $oggi;//le istruzioni php terminano con ; ?>'>
<input style='color:black; background-color: #999999;' type='submit' name ='cerca' value='Cerca'>
</td></tr></table>
</form>
</font>
<?php
//se non metti l'issete del form cerca ti fa casino
if(isset($_POST['cerca'])){
	$DB_host     = 'localhost';
	$DB_user     = 'XXXXX';
	$DB_password = 'XXXXX';
	$DB_name     = 'XXXXXXX';
	$b=date('ymd');
	$bi=date('d/m/y');
	$link = mysql_connect($DB_host, $DB_user, $DB_password);
	if (!$link) {
    	die ('Non riesco a connettermi: ' . mysql_error());
	}
	$db_selected = mysql_select_db($DB_name, $link);
	if (!$db_selected) {
    	die ("Errore nella selezione del database: " . mysql_error());
	}
	$txt = $_POST['txt'];//nessuna verifica ??
	echo "<td align='left'><p align='left'><font color='black' size='4'>
		<b>Elenco DDT $bi</b><a title='STAMPA' href='javascript:print();'>
		<input style='color:black;background-color:;' type='submit' value='Stampa'></a></font></p><td>";
		//non ti cinverrebbe al posto dell'input mettere un'immaginetta?
	$result = mysql_query("SELECT * FROM fatture WHERE doc LIKE 'DDT' && indice = '$txt' order by id desc");
	$num=mysql_num_rows($result);//forse intendevi $num=mysql_num_rows($result)
	//poi questo ti converrebbe trasmetterlo alla pag invio.php per verificare che tutti i campi siano stati compilate
	//il numero dei post pieni deve essere uguale a questo numero
	//lo puoi tramettere con un campo hidden 
	//e poi a che ti serve dovresti mettere un if
	/*
	if($num > 0){
		//tutto l'ambaradan del form
	}else{
		echo "non ci sono risultati, modifica dati di ricerca";
	}
	*/
	echo "<form method='POST' name='modulo' action='invio.php'  target='_blank'>";
	echo "<input name=\"numero\" type=\"hidden\" value=\"$num\">";
	echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
	echo "<tr> 
		<th align='center' width=''><font size='2'>Ragione sociale</th>
		<th align='center' width=''><font size='2'>Documento</th>
		<th align='center' width=''><font size='2'>Numero</th>
		<th align='center' width=''><font size='2'>Emissione</th>
		<th align='center' width=''><font size='2'>Codice cliente</th>
		<th align='center' width=''><font size='2'>Importo DDT</th>
		<th align='center' width=''><font size='2'>Data</th>
		<th align='center' width=''><font size='2'>Tipo</th>
		</tr>"; 
	$totale_importo = 0;
	while($row = mysql_fetch_array( $result )) { 
    	$id=$row['id']; 
    	echo "<tr> 
     		<td align='center'><font size='2'><input type='text' name='nome[]' maxlength='30' value='".$row['nome']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='doc[]' maxlength='30' value='".$row['doc']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='numero[]' maxlength='30' value='".$row['numero']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='emissione[]' maxlength='30' value='".$row['emissione']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='codcliente[]' maxlength='30' value='".$row['codcliente']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='importoDDT[]' maxlength='30' value='".$row['importoDDT']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='data[]' maxlength='30' value='".$row['data']."'></font></td> 
     		<td align='center'><font size='2'><input type='text' name='tipo[]' maxlength='30' value='".$row['tipo']."'></font></td> 
			</tr>";
     	$totale_importo += $row['importoDDT'];  
    	$i++;  //a che ti serve?
	}  
	echo "<td> <input type='button' value='Invia' onClick='Modulo()'></td>";
	echo "</table><br>";
	echo "</form>";
?>
<table style='border: 1px solid white' align='left' bgcolor='' border='0' width='100%' cellpadding='0' cellspacing='10'>
<td align="center"><font size='2'>Totale importo: <b><?php echo $totale_importo; ?>&nbsp;</b>euro</font></td>
</table>
<?php
}//fine if dell'isset
?>
</body>
</html>
come vedi ho tolto il js di verifica in quanto i campi di input diventano array
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Grazie. Appena arrivo a casa la provo subito. Ma la pagina invio.php resta com'è?
 
Discussioni simili
Autore Titolo Forum Risposte Data
S semplice query che non funziona :( PHP 3
A [MYSQL+PHP]Non riesco a fare la query!!!Penso sia semplice.. PHP 1
max75 query su due tabelle e dati doppioni MS Access 2
E Aiuto per query PHP 8
E Query differenza tra tabelle MySQL 5
E Query Alias PHP 4
T Query con date MS Access 1
K Inserimento query Errore 1366 PHP 4
L Query e selezione DB con $_POST PHP 2
M query update e delete PHP 0
A media degli elementi estratti da una query MySQL 0
S Passare query o utm alla pagina successiva Domini 1
O problema con query PHP 4
M Query PHP 8
R query DELETE non cancella i record PHP 1
G Query con i giorni della settimana MySQL 10
E Query annidate o cicli MySQL 1
C bottone query MySQL 0
T Query su due tabelle con totali Database 4
G AVVISO QUERY IN ESECUZIONE PHP 1
M Riportare in tabella HTML dati estratti con query SQL MySQL 0
S Selezionare ultimo record di una sotto query MySQL 27
G Menù a tendina di ricerca con query PHP 1
V Query per una somma PHP 2
F stampare a video i risultati della query PHP 1
L problema con query select PHP 2
D Query sum Database 1
M Visualizzazione a video risultati query php PHP 0
A form PHP prenotazione tramite query PHP 2
R Problema query con ricerca id numerico PHP 2
G Casella combinata in una query MS Access 4
R Aiuto con le query MS Access 2
Y query di DELETE PHP 4
V Query Oracle Oracle 0
L query somma PHP 8
W Query SQL Classic ASP 2
M Problemi con query a più tabelle PHP 3
Alex_70 Conteggio nella query PHP 0
elpirata Query per leggere dati da una tabella mysql e mostrarli a video in base a parametri passati tramite GET PHP 5
A nome file che contiene punto passato come parametro a query PHP 31
F query e form con select multipla PHP 17
M Problema su query JOIN in tre tabelle PHP 0
M Ordinare una query join PHP 2
Alex_70 Query ORDER BY PHP 18
G Problema ------- con Query PHP 1
G Problema con Query PHP 1
Alex_70 foreach explode query PHP 3
O query con date in formato stringa PHP 3
Tommy03 Unione query di 4 tabelle MySQL 1
I Fatal error: Query Failed! SQL: SELECT * INTO OUTFILE PHP 1

Discussioni simili