|
Posted by Jerry Stuckle on 09/26/05 11:35
zek2005 wrote:
> Hi!!!
>
> I need to retrieve the information of a database in 2 steps. First,
> depending on the number of a branch, I have to show in a combo the
> commercial campaigns available for that branch. Then when the user
> select one campaign I need to chow the customers of that campaign.
>
> I have two errors
> (http://www.historiadelpais.com.ar/bp/acciones_vigentes.php).
>
> First: As I do not have the second variable when I load the page I
> receive the first error.
> Second: When I enter a branch (example: 17 or 20), the combo box works
> but when I try to retrieve the customers I have another error.
>
> Thak you for your help!!!!
>
> Zek
<code snipped>
Your problem is you're using variables which have not been set yet.
This is caused by two different errors in your code.
First of all, register_globals should be off (if it isn't, turn it off!
If your host won't turn it off, get a new host!). Therefore, $suc
will not be set. You need to check $_POST['suc'] instead.
The second problem is the first time through $_POST['suc'] will not be
set the first time through. You also need to check for that.
Some changes to your code (not tested):
<html>
<head>
<title>Clientes</title>
<?php
$suc = isset($_POST['suc']) ? $_POST['suc'] : '';
$campania = isset($_POST['campania']) ? $_POST['campania'] : '';
?>
</head>
<body>
<p align="center"><u><b>Acciones Vigentes</b></u></p>
<form method="POST" action="<?=$PHP_SELF?>">
<p align="center"><b><font face="Tahoma"
size="2">Sucursal
</font></b><input type="text" size="6" name
="suc" value="<?php echo $suc;?>>
<input type="submit" value="Ingresar"></p>
</form>
<?PHP
$dbase = mysql_connect("localhost", user , pass);
mysql_select_db(historia,$dbase);
if($suc != '')
$respuesta = mysql_query("SELECT distinct codigo, descripcion
FROM `det_acciones`
INNER JOIN acciones
ON acciones.accion = det_acciones.codigo
WHERE oficial_id =$suc", $dbase);
else
$respuesta = false;
?>
<form method="POST" action="<?=$PHP_SELF?>">
<select name="campania">
<?PHP
printf("<option selected value=\"\"> Seleccionar Acción
</option>");
if ($repuesta) {
while($row = mysql_fetch_array($respuesta)) {
printf("<option value=\"%s\"> %s
</option>",$row["codigo"],$row["descripcion"]);
}
}
?>
</select>
<input type="hidden" name="suc" value="<?php echo $suc; ?>>
<input type="submit" value="Ver clientes">
</form>
<?PHP
if ($campania != "") {
$response = mysql_query("SELECT nombre
FROM `acciones`
WHERE oficial_id =$suc and accion=$campania", $dbase);
if ($response)
while($row = mysql_fetch_array($response))
{
echo($row[nombre]);
}
else
echo "MySQL Error: " . mysql_error() . "\n";
}
?>
</body>
</html>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|