Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

§_ladyshaolin_§

cláusula if, msg de erro

Recommended Posts

Olá!

Tô tentando fazer um formulário que vai carregar as infos de um combo só depois que o primeiro tiver alguma coisa selecionada, mas está aparecendo esse err:

 

Parse error: parse error, unexpected T_ELSE in /home/restricted/home/natuscosmeticos1/public_html/adm/teste_combo.php on line 36

 

Que é bem no else da minha cláusula if, estarei eu fechando ou abrindo e esquecendo de fechar alguma chave? Segue abaixo o código:

PHP

[*]<form action="" method="post" name="Cadastro">

[*]<table width="100" border="0" cellspacing="0" cellpadding="0">

[*] <tr>

[*] <td>Linha:</td>

[*] <td><select name="linha">

[*] <option selected value="">--Linha--</option>

[*]  <? 

[*] while($linha=mysql_fetch_array($sql)) { 

[*] echo "<option value=\"" . $linha["id_linha"] . "\">" . $linha["nome_linha"] . "</option>"; 

[*] } 

[*] ?>

[*] </select></td>

[*] </tr>

[*] <tr>

[*] <td>Categoria:</td>

[*] <td>

[*] <?php if($linha =="")

[*] { ?>

[*] <select name="categoria" size="1">

[*] <option selected>--Categoria--</option> 

[*] <?php }?>

[*] <?php 

[*] else

[*] $sql_cat = mysql_query("SELECT * FROM tb_produtos_categoria WHERE linha = '$linha' order by categoria ");

[*] while($categoria=mysql_fetch_array($sql_cat)) { 

[*] echo "<option value=\"" . $categoria["id_categoria"] . "\">" . $categoria["categoria"] . "</option>"; 

[*] } 

[*] ?>

[*]  </select></td>

[*] </tr>

[*] <tr>

[*] <td>Subcategoria:</td>

[*] <td><input type="text" name="textfield"></td>

[*] </tr>

[*] <tr>

[*] <td> </td>

[*] <td><input type="submit" name="Submit" value="Ok">

[*] <input type="reset" name="Submit2" value="Redefinir"></td>

[*] </tr>

[*]</table>

[*]

[*]

[*]</form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ninguém pode me dar uma luz... :(

Tentei mudar o código assim:

 

PHP

[*]

[*]<?php

[*]require "dsn.php";

[*]$sql = mysql_query("SELECT * FROM tb_produtos_linha order by nome_linha");

[*]$linha_sel="";

[*]?>

[*]<html>

[*]<head>

[*]<title>Untitled Document</title>

[*]<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

[*]

[*]</head>

[*]

[*]<body>

[*]

[*]<form action="" method="post">

[*]<table width="100" border="0" cellspacing="0" cellpadding="0">

[*] <tr>

[*] <td>Linha:</td>

[*] <td><select name=\"<?php $linha_sel?>\">

[*] <option selected>--Linha--</option>

[*]  <? 

[*] while($linha=mysql_fetch_array($sql)) { 

[*] echo "<option value=\"" . $id_linha["id_linha"] . "\">" . $linha["nome_linha"] . "</option>"; 

[*] } 

[*] ?>

[*] </select></td>

[*] </tr>

[*] <tr>

[*] <td>Categoria:</td>

[*] <td>

[*] <?php if(empty($linha_sel))

[*] { ?>

[*] <select name="categoria" size="1">

[*] <option selected>--Categoria--</option> 

[*] <?php }?>

[*] <?php 

[*] else

[*] $sql_cat = mysql_query("SELECT * FROM tb_produtos_categoria WHERE linha = '$id_linha' order by categoria ");

[*] while($categoria=mysql_fetch_array($sql_cat)) { 

[*] echo "<option value=\"" . $categoria["id_categoria"] . "\">" . $categoria["categoria"] . "</option>";

[*] } 

[*]}

[*] ?>

[*]  </select></td>

[*] </tr>

[*] <tr>

[*] <td>Subcategoria:</td>

[*] <td><input type="text" name="textfield"></td>

[*] </tr>

[*] <tr>

[*] <td> </td>

[*] <td><input type="submit" name="Submit" value="Ok">

[*] <input type="reset" name="Submit2" value="Redefinir"></td>

[*] </tr>

[*]</table>

[*]

[*]

[*]</form>

[*]</body>

[*]</html>

[*]

mas também não funcionou... só quero que a combo categoria seja carregada qdo for selecionado um valor na combo linha <_<

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se eu não me engano, o else deve estar no mesmo bloco (<? ?>) do if referente a ele.

Tente fazer assim:

 

PHP

[*]

[*] <?php if(empty($linha_sel)

[*] { ?> 

[*] <select name="categoria" size="1"> 

[*] <option selected>--Categoria--</option>

[*] <?php }

[*] else{

[*] $sql_cat = mysql_query("SELECT * FROM tb_produtos_categoria WHERE linha = '$id_linha' order by categoria ")

[*] while($categoria=mysql_fetch_array($sql_cat)) {

[*] echo "<option value=\"" . $categoria["id_categoria"] . "\">" . $categoria["categoria"] . "</option>"

[*] }

[*]} 

[*] ?> 

[*]

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.