Jump to content


Marianita

Member Since 21/11/2015
Offline Last Active 22/11/2015, 11:37
-----

Topics I've Started

erro no fecho da ligação ao db

21/11/2015, 21:57

boa noite, tenho o seguinte erro no código:

 

Warning: mysql_close() expects parameter 1 to be resource, null given in /home/rpublici/public_html/loja/incluir.php on line 71

 

...e alem disso não me está a inserir os produtos na tabela "produtos"... alguém me pode ajudar?

 

 

 

ficheiro: incluir.php

<html>
    <head>
        <title>Inserir Registos</title>
    </head>
    <body>
        <h2 align="center">Inserir Produtos</h2>
        <hr>

        <?
        //EXECUTA A LIGAÇÃO À BASE DE DADOS
        require_once("conecta.php");

        if(!isset($_POST["enviar"])){
        ?>

        <form method="POST" action="<? echo $_SERVER["PHP_SELF"]; ?>">
              <center>
                <br>
                <table border="0" cellpading="4" cellspacing="8"  bgcolor="#cfcfcf">
                    <tr>
                        <td align="right">Nome:</td>
                        <td><input type="text" name="nome" size="40"></td>
                    </tr>
                    <tr>
                        <td align="right">Descrição:</td>
                        <td><textarea rows="2" name="descricao" cols="30"></textarea></td>
                    </tr>
                    <tr>
                        <td align="right">Adicionais:</td>
                        <td><textarea rows="2" name="adicionais" cols="30"></textarea></td>
                    </tr>
                    <tr>
                        <td align="right">Preço:</td>
                        <td><input type="text" name="preco" size="40"></td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td align="right">
                            <input type ="hidden" name="enviar" value="S">
                            <input type="submit" value="Inserir Produto" name="incluir">
                        </td>
                    </tr>
                </table>
        </form>

        <?
        }else{

        //INSERE O PRODUTO
        if ($ligacao){
        $nome=$_POST["nome"];
        $descricao=$_POST["descricao"];
        $adicionais=$_POST['adicionais'];
        $preco=$_POST["preco"];
        $sql="insert into produtos values('','$nome','$descricao','$adicionais','$preco')";
        $res2=mysql_db_query("loja","$sql",$ligacao);

        //SE TUDO ESTIVER OK MOSTRA A MENSAGEM DE SUCESSO
        if ($res2){
        echo"<p align='center'>Produto incluido com sucesso!</p>";

        }else{

        //CASO EXISTA ALGUM ERRO MOSTRA O ERRO EXISTENTE
        $erro=mysql_error();
        echo "<p align='center'>Erro: $erro</p>";
        }}}

        //FECHA A LIGAÇÃO
        mysql_close($ligacao);
        ?>

        <p align="center"><a href="menu.php">Voltar</a></p>
    </body>
</html>


Problemas ao ligar a DB após inserir user e pass corretos

21/11/2015, 21:24

ola eu tenho este código: ficheiro autentica.php

 

<html>
<head>
<title>Untitled</title>
</head>
<body>

 

<html>
    <head>
        <title>Untitled</title>
    </head>
    <body>

        <?php
        require_once("conecta.php");
        //RECEBE OS DADOS DO FORMULÁRIO
        $utilizador = $_POST["txtUser"];
        $senha = $_POST["txtSenha"];
        // CÓDIGO QUE VAI SELECIONAR O REGISTRO QUE É IGUAL AO USERNAME E A SENHA DIGITADOS
        $sql = mysql_query("SELECT U.username, U.nome FROM utilizadores U WHERE U.username = '$utilizador' AND U.senha = '$senha'") or die("ERRO NO COMANDO SQL");
        //COLOCA NA VAIRÁVEL $row A QUANTIDADE DE LINHAS AFETADAS PELA CONSULTA
        $row = mysql_num_rows($sql);
        //VERIFICA O VALOR DA VARIÁVEL $row, SE FOR >0 INDICA QUE A CONSULTA ENCONTROU O UTILIZADOR NA TABELA.
        if ($row == 0) {
            echo "Utilizador/Senha inválidos";
        } else { //PEGA NOS DADOS
            $id = mysql_result($sql, 0, "username");
            $nome = mysql_result($sql, 0, "nome");
            //INICIA A SESSÃO
            session_start();
            //GRAVA AS VARIÁVEIS NA SESSÃO
            $_SESSION[id] = $id;
            $_SESSION[nome] = $nome;
            //REDIRECIONA PARA A PÁGINA QUE VAI EXIBIR OS PRODUTOS
            Header("Location: menu.php");
        }
        ?>

    </body>
</html>

-----------------------------

AGORA O PROBLEMA:

 

acontece que após digitar o username e password corretos que estão inseridos na DB dá-me uma serie de erros. A DB é a seguinte:

username senha nome email cidade pais   victor viana2015 nome teste@email.com lisboa

portugal

 

e os erros que me aparecem após clicar para entrar são:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/rpublici/public_html/loja/autentica.php:7) in /home/rpublici/public_html/loja/autentica.php on line 27

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/rpublici/public_html/loja/autentica.php:7) in /home/rpublici/public_html/loja/autentica.php on line 27

Warning: Cannot modify header information - headers already sent by (output started at /home/rpublici/public_html/loja/autentica.php:7) in /home/rpublici/public_html/loja/autentica.php on line 32

 

preciso de ajuda! o que tou a fazer é um sistema que me permita inserir produtos por categoria/subcategoria numa DB


resolvido


IPB Skin By Virteq