0

All I want is to display my search term in the url. Somehow I am not able to get it.

<?php $string = stripcslashes(isset($_GET['string']));?>

<form action="index.php?string=<?php echo $string;?>" method="post">
    <input name="string" type="text" class="inputbox" id="String" 
    value="<?php echo stripcslashes(isset($_REQUEST["string"])); ?>" 
    size="40" style="width:250px"/>
</form>

Also there is always a 1 displaying in my search field after I make a search. I am sure that is what is messing it up.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150

3 Answers3

2

The code <?php $string = stripcslashes(isset($_GET['string']));?> is going to return you either a 1 or 0.

You have to do like this..

<?php
if(isset($_GET['string']))
{
$string = stripcslashes($_GET['string']);
}
?>
<form action="index.php?string=<?php echo $string;?>" method="post"><input name="string" type="text" class="inputbox" id="String" value="<?php echo $string; ?>" size="40" style="width:250px"/></form>
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

isset() function returns a boolean value, not the value of the variable itself.

From the manual page:

bool isset ( mixed $var [, mixed $... ] )

If you're trying to check if the variable $_GET['string'] is defined and then set its value equal to stripcslashes($_GET['string']), then you can do it as follows, using a ternary statement:

$string = (isset($_GET['string'])) ? stripcslashes($_GET['string']) : '';
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • all i had to do was change from post to get – user3077454 Dec 15 '13 at 19:32
  • @user3077454: Ah! I didn't notice the form `method`. Of course, it wouldn't work with `POST`. However, you'd have noticed this easily if you had indented your code properly. Anyway, I'm glad you solved the issue :) – Amal Murali Dec 15 '13 at 19:35
0
<?php $string = (isset($_GET['string']))?stripcslashes($_GET['string']):'';?>
Dinesh Saini
  • 2,917
  • 2
  • 30
  • 48