# pass a text information to a php page using link



## bukaida (May 22, 2008)

I want to pass a text information to a php page using link. The following code will display my intention

```
<html> 
<head><title>Display by id</title> 
</head> 
<body> 
<form > 
<table align="center"> 
<tr><td><b>Enter the Book id:</b></td> 
 <td><input type="text" name="id" size="10"></td></tr> 
  
 <tr><td><a href="search_prev.php"><img src="images/prev.JPG" alt="" width="90" height="34" border="0"></a></td> 
 <td><a href="search_by_id.php"><img src="images/Go.JPG" alt="" width="71" height="34" border="0"></a></td> 
 <td><a href="search_next.php"><img src="images/next.JPG" alt="" width="90" height="34" border="0"></a></td> 
 </tr> 
 </table> 
</form> 
</body> 
</html>
```

There is a simple textbox. Below it there are three hyperlinks containing the image(like a button). 
The idea is to go to three different php pages (one at a time, depending on the click) with the textbox value so that they can be used in those pages(by $_POST/GET/REQUEST or any other method).How to do that? Please help.


----------



## victor_rambo (May 22, 2008)

Sorry but I am not sure what you exactly want:

May be you want to try this out:

```
html form code goes here
```


```
<?php
if(isset($_POST["id"]))
{
include($id."php");//must validate the file name to prevent remote file inclusion attack.

//or


//fetch data from database
}
?>
```


----------



## amitava82 (May 23, 2008)

AFAIK, without javascript its not possible. Here is how i'd do it:

1. Your html page:

```
<html> 
<head><title>Display by id</title> 
<script language="Javascript">
function button1()
{
    document.Form1.action = "search_prev.php";
    document.Form1.submit();
    return true;
}

function button2()
{
    document.Form1.action = "search_by_id.php";
    document.Form1.submit();
    return true;
}

function button3()
{
    document.Form1.action = "search_next.php";
	document.Form1.submit();
    return true;
}
</script>
</head> 
<body> 

<table align="center"> 
<form method="post" name="Form1" id="Form1"> 
<tr><td><b>Enter the Book id:</b></td> 
 <td><input type="text" name="id" size="10"></td></tr> 
  
 <tr>
 <td><input type="image" name="search_prev" src="images/prev.JPG" width="71" height="34" onclick="return button1()"></td> 
 <td><input type="image" name="search_by_id" src="images/Go.JPG" width="71" height="34" onclick="return button2()"></td> 
 <td><input type="image" name="search_next" src="images/next.JPG" width="71" height="34" onclick="return button3()"></td> 
 </tr>  
 </form> 
 </table> 
</body> 
</html>
```
2. Your php page:

```
<?php
if (isset($_POST['id'])) {
$value = $_POST['id'];
}
?>
```
Now the form value will be stored in $value and u can use it anytime you want. Say, you can echo it out:

```
echo $value;
```
You should also take security measures before using he value. Such as, escape sql special character using function *mysql_real_escape_string*, stripe html tags using *strip_tags* in order to prevent cross site scripting attack.


----------



## bukaida (May 27, 2008)

Is there any way to avoid the button? I mean by using the GET method with hyperlink because I want to have the coloured picture of Prev, Next etc to be retained..Security is not a major concern here.


----------



## amitava82 (May 27, 2008)

Where am I using any buttons? 'button' are just function names.. Did u even try the code?


----------

