[PHP] Re: [PHP-DB] Re: [PHP] Passing variables to a PHP script on clicking a hyperlink

2007-08-24 Thread Goltsios Theodore


I think that you can also do that buy making a drop down list with the 
available databases and pass the chosen database to another (or perhaps 
the same) script and make the queries and output results there. You can 
catch the posted or got option buy using the $_REQUEST array ($_GET and 
$_POST are included in that like a less lame solution). Let's say you 
have a databases.php script that passes options to con_query.php the 
code could something like that:


*databases.php:*
?php

$label = Choose a database :;
$database = array('database1','database3','database3');

# Print the headers
   print 'htmlheadmeta http-equiv=content-type 
content=text/html; charset=UTF-8titleDatabase 
selection/title/headbody no-repeat;';
   print 'table class=outer border=0 width=100% cellpadding=10 
cellspacing=10';

   print '   trtd height=92px colspan=2/td/tr';
  
# Print the drop down form

   print form name='dtbases' action='con_query.php' method='POST';
   print 'table border=0 trtdtable 
class=invistrtdnbsp;/td/tr';

   print trtdb$label/b/tdtdselect name='database';
   foreach ($database as $value){
   print option value='$value'$value/option;
}
   print /td/tr/select;
   print trtdnbsp;/td/tr;
   print trtd colspan=2 align=centerinput type=submit 
value='Submit'/td/tr;


?

*con_query.php:*
?php
$database = $_REQUEST['database'];
print The user chose database : .$database;
?

You can take now the $database containing the one chosen by the user and 
connect and query whatever you wan't.


Have fun.

mike wrote:

On 8/23/07, Suamya Srivastava [EMAIL PROTECTED] wrote:
  

Hello,

How can I pass variables on clicking a hyperlink to a PHP script? I have 5
hyperlinks, all pointing to the same PHP script. However, on clicking each
hyperlink a different value of the variable needs to be passed to the PHP
script.
i.e.  I have 5 databases from which I want to obtain information, however
the information should be displayed only when the user clicks on the
hyperlink for that database. How can I pass the database name to the PHP
script? How would the script know which database to get information from?

I am new to PHP so any help would be greatly appreciated. I hope my
question is clear.



use GET

foo.php?param=value

or you could use POST by using some client-side javascript to do a
form submit with key/value pairs.

this is a *very* simple operation... all web-enabled languages
understand HTTP POST/GET/etc. - those are the main ways of exchanging
data between client/server.

  


[PHP] Re: [PHP-DB] Re: [PHP] Passing variables to a PHP script on clicking a hyperlink

2007-08-24 Thread Goltsios Theodore


I thought I just did a comment and suggested that it is a lame solution 
to use $_REQUEST plus I did not know witch of the two method  (POST or 
GET) would be appropriate so I picked up the lame way :-) .


mike wrote:

On 8/24/07, Goltsios Theodore [EMAIL PROTECTED] wrote:
  

the posted or got option buy using the $_REQUEST array ($_GET and $_POST are
included in that like a less lame solution). Let's say you have a



Please do not encourage the use of $_REQUEST.

You might as well just tell people to enable register_globals again.

Use $_GET, $_POST, $_SESSION, $_COOKIE, $_SERVER, etc. for the
appropriate source of data. $_REQUEST is laziness and introduces most
of the same issues that was the reasoning behind disabling
register_globals to begin with.

(As for dropdowns, that's just an in-browser method of collecting data
and sending the key/value pairs in POST or GET... IMHO the HTML
portion should already be known before someone steps into the realm of
PHP and server-side programming)

- mike