Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 24th, 2005, 04:15 AM
zek2005
Guest
 
Posts: n/a
Default Help with $PHP_SELF

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..._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

This is the code:

<html>
<head>
<title>Clientes</title>
</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&nbsp;&nbsp;&nbsp;&nbsp;
</font></b><input type="text" size="6" name
="suc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;
<input type="submit" value="Ingresar"></p>
</form>

<?PHP

$dbase = mysql_connect("localhost", user , pass);
mysql_select_db(historia,$dbase);

$respuesta = mysql_query("SELECT distinct codigo, descripcion
FROM `det_acciones`
INNER JOIN acciones
ON acciones.accion = det_acciones.codigo
WHERE oficial_id =$suc", $dbase);
?>
<form method="POST" action="<?=$PHP_SELF?>">
<select name="campania">

<?PHP

printf("<option selected value=\"\"> Seleccionar Acción
</option>");
while($row = mysql_fetch_array($respuesta))
{
printf("<option value=\"%s\"> %s
</option>",$row["codigo"],$row["descripcion"]);
}

?>
</select>
<input type="submit" value="Ver clientes">
</form>

<?PHP
$response = mysql_query("SELECT nombre
FROM `acciones`
WHERE oficial_id =$suc and accion=$campania", $dbase);

while($row = mysql_fetch_array($response))
{
echo($row[nombre]);
}
?>

</body>
</html>

  #2  
Old December 24th, 2005, 07:25 AM
Ulitin S.S.
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF


"zek2005" <esapoznik@gmail.com> wrote in message
news:1135397069.551861.126470@g49g2000cwa.googlegr oups.com...
Hi!!!
<?PHP

$dbase = mysql_connect("localhost", user , pass);
mysql_select_db(historia,$dbase);
.............

What is historia???
The variable is not initialized.


  #3  
Old December 24th, 2005, 07:25 AM
Ulitin S.S.
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF


"zek2005" <esapoznik@gmail.com> wrote in message
news:1135397069.551861.126470@g49g2000cwa.googlegr oups.com...
Hi!!!
<?PHP

$dbase = mysql_connect("localhost", user , pass);
mysql_select_db(historia,$dbase);
.............

What is historia???
The variable is not initialized.


  #4  
Old December 24th, 2005, 10:05 AM
Anonymous
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF

zek2005 wrote:
[color=blue]
> $dbase = mysql_connect("localhost", user , pass);[/color]

What are user and pass? Variables which contain the user and the
password as strings? Then it should be $user and $pass. Or are these the
actual user and password to the database? Then these are constant
strings and have to be quoted: "user" and "pass" would be right
(replaced with the real ones of course).
[color=blue]
> mysql_select_db(historia,$dbase);[/color]

Exactly the same error here with historia. Either $historia or
"historia" depending on what you actually meant.

Bye!
  #5  
Old December 24th, 2005, 12:45 PM
zek2005
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF

Hi friends!!!

historia is the database and user and pass are the real user and
password of the database (I did not write the correct one for
security). The connection to the database works fine...the problem is
before with the combo box and the detail of customers.

Thank you!

  #6  
Old December 24th, 2005, 12:55 PM
Sean
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF

There is something wrong with this query.

$response = mysql_query("SELECT nombre
FROM `acciones`
WHERE oficial_id =$suc and accion=$campania", $dbase);

Change to this:

$response = mysql_query("SELECT nombre
FROM `acciones`
WHERE oficial_id =$suc and accion=$campania", $dbase);
if (!$response ) {
die('Invalid query: ' . mysql_error());
}

So you can see what the error is. If accion is a varchar or some sort
of string you might need to change it to:

$response = mysql_query("SELECT nombre
FROM `acciones`
WHERE oficial_id =$suc and accion='$campania'",
$dbase);

Buts that's a complete guess, I am not sure what is wrong with the
query.

  #7  
Old December 24th, 2005, 01:25 PM
Janwillem Borleffs
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF

zek2005 wrote:[color=blue]
> I have two errors
> (http://www.historiadelpais.com.ar/bp..._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.
>[/color]

Sounds like a classical register_globals problem. Look it up in your php.ini
file; when it's omitted or disabled, $PHP_SELF won't work, and you should
use $_SERVER['PHP_SELF'] instead. This also applies to form variables,
which, in your case, will be stored in the $_POST array.
[color=blue]
> $dbase = mysql_connect("localhost", user , pass);
> mysql_select_db(historia,$dbase);
>[/color]

Already addressed by others in the thread. The reason that the bareword
'historia' works is that PHP's kind enough to create a variable on the fly
with the name as its value. Be aware, however, that this isn't good practise
and raises a notice on systems with the default error_reporting level.

JW


  #8  
Old December 24th, 2005, 03:05 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: Help with $PHP_SELF

zek2005 wrote:[color=blue]
> 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..._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[/color]

<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&nbsp;&nbsp;&nbsp;&nbsp;
</font></b><input type="text" size="6" name
="suc" value="<?php echo $suc;?>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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
==================
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles