By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Help with $PHP_SELF

P: n/a
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>

Dec 24 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"zek2005" <es*******@gmail.com> wrote in message
news:11**********************@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.
Dec 24 '05 #2

P: n/a

"zek2005" <es*******@gmail.com> wrote in message
news:11**********************@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.
Dec 24 '05 #3

P: n/a
zek2005 wrote:
$dbase = mysql_connect("localhost", user , pass);
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).
mysql_select_db(historia,$dbase);


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

Bye!
Dec 24 '05 #4

P: n/a
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!

Dec 24 '05 #5

P: n/a
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.

Dec 24 '05 #6

P: n/a
zek2005 wrote:
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.

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.
$dbase = mysql_connect("localhost", user , pass);
mysql_select_db(historia,$dbase);


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
Dec 24 '05 #7

P: n/a
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..._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&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.
js*******@attglobal.net
==================
Dec 24 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.