6 Replies - 3732 Views - Last Post: 26 May 2009 - 07:14 AM Rate Topic: -----

#1 sosippus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-May 09

how to link results from a php/html page?

Posted 25 May 2009 - 07:18 PM

Hello!
I have a page that accepts user input and then generates this page:
Posted Image

The problem is, I dont know how to generate different links, based on the choice of the user. The user should click one of those links and it should redirect into a php file that contains information, depending on the choice.

Since this is a large database, the final php file to be displayed can't be created manualy for every possible choice. But I dont know how to have a "GET" variable from that links... That is, even if i can create different links, I dont know how to create the pages that they may link to...

Here's the linking script (in case it helps):

<html>
<head>
<center><title> DB</title></center>
</head>
<body>
<body style="background-color:#E4F4F9;">

<?php
include 'config.php';
$pesquisa = $_GET['pesquisa'];
$escolha = $_GET['choice'];


if($escolha=='compoundname'){
	$arnome=array();

	$nome= mysql_query("SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'");
	   while ($metear = mysql_fetch_array($nome)) {
		array_push($arnome,$metear['name']);
	}

	echo '<pre><b>Search Results:</b></br></pre>';
	$lenght = count($arnome);
	foreach ($arnome as $elemento){
		echo "<a href=\"localhost/.$elemento.php\">$elemento</br></br></a>";
	}}
?>
</form>
</body>
</html>


I'd appreciate a lot if someone could tell me how to have something similar to a "POST" or "GET" instance for each link generated. Thanks a lot for your time!

Is This A Good Question/Topic? 0
  • +

Replies To: how to link results from a php/html page?

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 13,557
  • Joined: 08-August 08

Re: how to link results from a php/html page?

Posted 25 May 2009 - 08:02 PM

PHP files contain programs, not information. Programs process information. Think of php as a programming language and html as the data that it outputs along with data from your database. Then write a php program that generates the output you're looking for instead of trying to slap some php inside of html.
Was This Post Helpful? 0
  • +
  • -

#3 sosippus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-May 09

Re: how to link results from a php/html page?

Posted 25 May 2009 - 08:11 PM

View PostCTphpnwb, on 25 May, 2009 - 07:02 PM, said:

PHP files contain programs, not information. Programs process information. Think of php as a programming language and html as the data that it outputs along with data from your database. Then write a php program that generates the output you're looking for instead of trying to slap some php inside of html.


Well, I tried using a HTML file that would have a "include some.php", but I had a 403 permissions error and I couldnt solve that... :S That's why I'm trying to use a php file with some html tags in it
Was This Post Helpful? 0
  • +
  • -

#4 sosippus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-May 09

Re: how to link results from a php/html page?

Posted 26 May 2009 - 02:47 AM

Here's what I have in that error_log whenever it returns that 403 error.:
[Tue May 26 10:42:18 2009] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map POST /%3C?php%20echo%20$_SERVER[%27PHP_SELF%27];?%3E HTTP/1.1 to file, referer: http://localhost/index3.html



Thanks a lot for your help
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 13,557
  • Joined: 08-August 08

Re: how to link results from a php/html page?

Posted 26 May 2009 - 05:58 AM

Let's start by looking at the program.
<?php
include 'config.php';
$pesquisa = $_GET['pesquisa'];
$escolha = $_GET['choice'];


if($escolha=='compoundname'){
    $arnome=array();

    $nome= mysql_query("SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'");
       while ($metear = mysql_fetch_array($nome)) {
        array_push($arnome,$metear['name']);
    }

    echo '<pre><b>Search Results:</b></br></pre>';
    $lenght = count($arnome);
    foreach ($arnome as $elemento){
        echo "<a href=\"localhost/.$elemento.php\">$elemento</br></br></a>";
    }}
?>


The first thing you want to do is make sure the query is correct, so instead of
    $nome= mysql_query("SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'");

let's do:
    $query="SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'";
    echo $query."<br>";
    $nome= mysql_query($query);


What does the query look like?

By the way, using:
$pesquisa = $_GET['pesquisa'];

is a huge security issue, but you can deal with that after you get your code working.

Next, what does this produce?

    foreach ($arnome as $elemento){
        echo "<a href=\"localhost/.$elemento.php\">$elemento</br></br></a>";
    }}

You can look at the html by viewing the source in your browser.
Was This Post Helpful? 0
  • +
  • -

#6 sosippus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-May 09

Re: how to link results from a php/html page?

Posted 26 May 2009 - 07:08 AM

Hello! I really appreciate your help! Thanks a lot for what you have allready done to help me. Now, to reply to your questions:

View PostCTphpnwb, on 26 May, 2009 - 04:58 AM, said:

Let's start by looking at the program.

The first thing you want to do is make sure the query is correct, so instead of
    $nome= mysql_query("SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'");

let's do:
    $query="SELECT name FROM `names` WHERE `name` REGEXP '".$pesquisa."'";
    echo $query."<br>";
    $nome= mysql_query($query);


What does the query look like?

To tell the truth, I'm allready able to select and get links printed. It prints all I wanted (just like you can see in the thread starting image).

Quote

By the way, using:
$pesquisa = $_GET['pesquisa'];

is a huge security issue, but you can deal with that after you get your code working.

I dont know if I understood correctly what you meant by "security issue", but if it is related with the url displaying the search query inserted by the user, this isn't a problem.
It is not information that must be hidden, as it is just data from chemical compounds and stuff like that, avayable in the web. Dont worry about that ;D

Quote

Next, what does this produce?

    foreach ($arnome as $elemento){
        echo "<a href=\"localhost/.$elemento.php\">$elemento</br></br></a>";
    }}

You can look at the html by viewing the source in your browser.

Like I mentioned a bit above, the output is those links in the image in the first post.

My main issue here is:
First:How to produce dynamic links, one link for each of the search results (I don't want the links that are in the first image to be the same).
Second:I want them to link to a script that, depending on the link chosen, it will use the user's choice to produce a different results. So, I don't know how to use the information from dynamic links... :S
to sum all I want:The links should be associated with a variable (probably a $_GET or something like that) that will be interpreted in another php file.

Thanks a lot!

This post has been edited by sosippus: 26 May 2009 - 07:10 AM

Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 13,557
  • Joined: 08-August 08

Re: how to link results from a php/html page?

Posted 26 May 2009 - 07:14 AM

A ) It doesn't matter what the output looks like on the screen. It's the html that I'm asking about.

B ) Printing links is NOT working, or you wouldn't be asking the question. See (A).

C ) Security issue: Google: SQL injection.

This post has been edited by CTphpnwb: 26 May 2009 - 07:15 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1