Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Sou iniciante no PHP e estou aprendendo.
Quando montei esse código tudo funcionou, o erro abaixo foi quando tentei fazer duas consultas no banco.
<?php
$host = "127.0.0.1";
$dbuser = "root";
$dbpass = "123";
$dbdatabasename = "teste";
$rs = mysqli_connect ( $host, $dbuser, $dbpass ) or die ( "Could not connect database" );
mysqli_select_db ( $rs, $dbdatabasename ) or die ( "Could not select database" );
$mes = strftime ( "%m", time () );
$totalentrada = "0";
$i = "0";
function selectmes($txt) {
switch ($txt) {
case 1 :
$mess = "Janeiro";
break;
case 2 :
$mess = "Fevereiro";
break;
case 3 :
$mess = "Março";
break;
case 4 :
$mess = "Abril";
break;
case 5 :
$mess = "Maio";
break;
case 6 :
$mess = "Junho";
break;
case 7 :
$mess = "Julho";
break;
case 8 :
$mess = "Agosto";
break;
case 9 :
$mess = "Setembro";
break;
case 10 :
$mess = "Outubro";
break;
case 11 :
$mess = "Novembro";
break;
case 12 :
$mess = "Dezembro";
break;
}
return $mess;
}
$entradahtml = "<table border='0' cellpadding='4' width='100%'>";
if ($query_entrada = mysqli_query ( $rs, "SELECT * FROM entrada where Month(data)='$mes'" )){
while ( $rs = mysqli_fetch_array ( $query_entrada ) ) {
if ($i % 2 == 1) {
$cor = "#f3f3f3";
} else {
$cor = "#ffffff";
}
$entradahtml .= " <tr>";
$entradahtml .= " <td><font face=arial size=1><b>" . strftime ( "%d", strtotime ( $rs ["data"] ) ) . " de " . selectmes ( strftime ( "%m", strtotime ( $rs ["data"] ) ) ) . "</b></font></td>";
$entradahtml .= " <td></td>";
$entradahtml .= " </tr>";
$entradahtml .= " <tr>";
$entradahtml .= " <td bgcolor='.$cor.'>" . $rs ["descricao"] . "</td>";
$entradahtml .= " <td bgcolor='.$cor.' ><a href='default.php?opcao=excluir_entrada&id=" . $rs ["id"] . "><font color=red>x</font></a> <font face=arial size=2>" . substr ( $rs ["descricao"], 0, 30 ) . "...</font></td>";
$entradahtml .= " <td bgcolor='.$cor.' align='center' width='70'><font face=arial size=2>" . number_format ( $rs ["valor"], 2 ) . "</font></td>";
$entradahtml .= " </tr>";
$entradahtml .= "</table>";
$i ++;
}
}
echo $entradahtml;
Se eu apagar daqui até o final a parte de cima funciona, mas quando coloco essa segunda parte provoca o erro. Mas se reparar o código é idêntico eu copie e colei, troquei apenas os comandos necessários.
Os dois códigos funcionam isolados, juntos na mesma página não.
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
$saidahtml = "<table border='0' cellpadding='4' width='100%'>";
if ($query_saida = mysqli_query ( $rs, "SELECT * FROM saida where Month(data)='$mes'" )){
while ( $rs = mysqli_fetch_array ( $query_saida ) ) {
if ($i % 2 == 1) {
$cor = "#f3f3f3";
} else {
$cor = "#ffffff";
}
$saidahtml .= " <tr>";
$saidahtml .= " <td><font face=arial size=1><b>" . strftime ( "%d", strtotime ( $rs ["data"] ) ) . " de " . selectmes ( strftime ( "%m", strtotime ( $rs ["data"] ) ) ) . "</b></font></td>";
$saidahtml .= " <td></td>";
$saidahtml .= " </tr>";
$saidahtml .= " <tr>";
$saidahtml .= " <td bgcolor='.$cor.'>" . $rs ["descricao"] . "</td>";
$saidahtml .= " <td bgcolor='.$cor.' ><a href='default.php?opcao=excluir_entrada&id=" . $rs ["id"] . "><font color=red>x</font></a> <font face=arial size=2>" . substr ( $rs ["descricao"], 0, 30 ) . "...</font></td>";
$saidahtml .= " <td bgcolor='.$cor.' align='center' width='70'><font face=arial size=2>" . number_format ( $rs ["valor"], 2 ) . "</font></td>";
$saidahtml .= " </tr>";
$saidahtml .= "</table>";
$i ++;
}
}
echo $saidahtml;
mysqli_close($rs);
?>
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /var/www/financeiro/index.php on line 97
Parte do código linha 97
if ($query_saida = mysqli_query ( $rs, "SELECT * FROM saida where Month(data)='$mes'" )){
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in /var/www/financeiro/index.php on line 128
Parte do código linha 128
mysqli_close($rs);
Porque está dando o erro, se os códigos isolados funcionam?
Carregando comentários...