+ Responder ao Tópico



  1. #1

    Padrão Loja virtual em PHP

    Olá, pessoal. Estou desenvolvendo uma loja virtual em PHP. Estou criando a página de categorias. Nesta página, quando clico no link de menu categorias é pra aparecer só a lista de categorias. E ao clicar em inserir ou alterar neste form, é pra aparecer o form de inserção só. São esses dois forms. O código é o seguinte:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    .style2 {
    font-size: 12px;
    font-weight: bold;
    }
    -->
    </style>
    <link href="Estilos.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <table align="center">
    <tr>
    <td colspan="2" valign="top"><?php include "cabecalho.php"; ?></td>
    </tr>
    <tr>
    <td width="202" height="59" align="center" valign="top"><?php include "menu.php"; ?></td>
    <td width="529" align="left"><table width="100%">
    <tr>
    <td height="291" valign="top"><div align="center" class="style2">
    <p class="style2">Categoria</p>
    <p class="style2">
    <? if ($acao != "") {
    $sql = mysql_query ("SELECT * from Categorias Where id_categoria = $id");?>

    <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF ?>">
    <table width="300" border="1" align="center" cellpadding="2">
    <tr>
    <td width="98" class="style2">Categoria</td>
    <td width="190"><label>
    <input name="txt_categoria" type="text" id="txt_categoria" size="35" />
    </label></td>
    </tr>
    <tr>
    <td height="41" colspan="2"><label>
    <div align="center">
    <input type="submit" name="button" id="button" value="OK" />
    </div>
    </label></td>
    </tr>
    </table>
    </form>
    <? } else { ?>
    <table width="317" border="1" cellpadding="0">
    <tr>
    <td width="206">Categorias</td>
    <td colspan="2"><div align="center">Ação</div></td>
    </tr>
    <? $sql = mysql_query("Select * from categorias");
    while ($coluna = mysql_fetch_array($sql)) { ?>

    <tr>
    <td><? echo $coluna[categoria] ?></td>
    <td width="53"><img src="../Imagens/alterar_registro.gif" width="24" height="24" /></td>
    <td width="50"><img src="../Imagens/delete.gif" width="24" height="24" /></td>
    </tr>
    <? } ?>
    <tr>
    <td height="19" colspan="3" align="right" valign="top"><label>
    <img src="../Imagens/novo_registro.gif" alt="" width="81" height="24" />
    <div align="right"></div>

    </label></td>
    </tr>
    </table>
    <? } ?>
    </div></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td height="20" colspan="2" valign="top"><?php include "rodape.php"; ?></td>
    </tr>
    </table>
    </body>
    </html>

    Acontece que o código em PHP não está sendo executado. Os dois forms estão sendo exibidos juntos. O código que é pra ser executado está em vermelho.
    Alguém pode dar uma força? Obrigada.

  2. #2

    Padrão Re: Loja virtual em PHP

    Citação Postado originalmente por DaianaMowry Ver Post
    Olá, pessoal. Estou desenvolvendo uma loja virtual em PHP. Estou criando a página de categorias. Nesta página, quando clico no link de menu categorias é pra aparecer só a lista de categorias. E ao clicar em inserir ou alterar neste form, é pra aparecer o form de inserção só. São esses dois forms. O código é o seguinte:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    .style2 {
    font-size: 12px;
    font-weight: bold;
    }
    -->
    </style>
    <link href="Estilos.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <table align="center">
    <tr>
    <td colspan="2" valign="top"><?php include "cabecalho.php"; ?></td>
    </tr>
    <tr>
    <td width="202" height="59" align="center" valign="top"><?php include "menu.php"; ?></td>
    <td width="529" align="left"><table width="100%">
    <tr>
    <td height="291" valign="top"><div align="center" class="style2">
    <p class="style2">Categoria</p>
    <p class="style2">
    <? if ($acao != "") {
    $sql = mysql_query ("SELECT * from Categorias Where id_categoria = $id");?>

    <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF ?>">
    <table width="300" border="1" align="center" cellpadding="2">
    <tr>
    <td width="98" class="style2">Categoria</td>
    <td width="190"><label>
    <input name="txt_categoria" type="text" id="txt_categoria" size="35" />
    </label></td>
    </tr>
    <tr>
    <td height="41" colspan="2"><label>
    <div align="center">
    <input type="submit" name="button" id="button" value="OK" />
    </div>
    </label></td>
    </tr>
    </table>
    </form>
    <? } else { ?>
    <table width="317" border="1" cellpadding="0">
    <tr>
    <td width="206">Categorias</td>
    <td colspan="2"><div align="center">Ação</div></td>
    </tr>
    <? $sql = mysql_query("Select * from categorias");
    while ($coluna = mysql_fetch_array($sql)) { ?>

    <tr>
    <td><? echo $coluna[categoria] ?></td>
    <td width="53"><img src="../Imagens/alterar_registro.gif" width="24" height="24" /></td>
    <td width="50"><img src="../Imagens/delete.gif" width="24" height="24" /></td>
    </tr>
    <? } ?>
    <tr>
    <td height="19" colspan="3" align="right" valign="top"><label>
    <img src="../Imagens/novo_registro.gif" alt="" width="81" height="24" />
    <div align="right"></div>

    </label></td>
    </tr>
    </table>
    <? } ?>
    </div></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td height="20" colspan="2" valign="top"><?php include "rodape.php"; ?></td>
    </tr>
    </table>
    </body>
    </html>

    Acontece que o código em PHP não está sendo executado. Os dois forms estão sendo exibidos juntos. O código que é pra ser executado está em vermelho.
    Alguém pode dar uma força? Obrigada.
    Nao estou vendo a opção (login,senha, banco de dados) que conecta no BD.

  3. #3

    Padrão Re: Loja virtual em PHP

    Está n página de conexão. Não está listando os registros. E ao clicar no menu categoria é pra exibir só o form da lista de categorias. E não o da inserção.

  4. #4
    Moderador Avatar de Bruno
    Ingresso
    Nov 2002
    Localização
    Guarapuava-PR
    Posts
    4.181
    Posts de Blog
    1

    Padrão Re: Loja virtual em PHP

    bom vamos la mule


    primeiro o que o amigo fsoaress escreveu esta exato mesmo que naum seja insert vc esta tentando fazer um select que precisa se conectar no mysql
    seguno
    a variavel acao
    <? if ($acao != "") {
    $sql = mysql_query ("SELECT * from Categorias Where id_categoria = $id");?>
    no caso comparando a variavel acao for diferente que nada ele cria uma variavel sql ate ai normal
    e vai criar o form sem os dados do banco ate pq vc naum fez o o fatch array

    ai no if caso o igual a nada ele vai fazer um while da tabela inteira e jogar pra vc os dados
    ate ai tudo certo


    vc vai precisar se conectar no mysql primeiro