Jump to content

Help needed with get and post??


andy_b_1502

Recommended Posts

Hello, i would like to know why this script isnt working the way i want it to:

 

<form method="get" action="localarea.php">
<a href="localarea.php"><?php $_POST[""" .$var. ""</p>"]; 
echo """ .$var. ""</p>";?></a>
</form>

 

Where the [""" .$var. ""</p>"] is the result of a search by the user. I'm trying to take that result from the form and post it on "localarea.php".

 

So far it just displays "Array ( )" where i would like it to display the users search result? any suggestions on this one?

 

If you guys need any more information i will try my best to provide. Thank in advance for any help

Link to comment
https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/
Share on other sites

Sorry it wasnt clear. I didnt want to post the whole script to confuse further, that form sits under a script for displaying the results of a user search. What i want basically is to grab that result (whatever it may be), make it a clickable link and display that result on the target page using php, im pretty sure this can be done just wondering in what way and how? $_GET or $_POST im not sure?

 

 

I feel that the whole code is needed, sorry if it wasn't but it may help?:

 

<?php

// Get the search variable from URL
  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10; 

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("xxxx","xxxx","xxxxx"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("removalspacelogin") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "(SELECT postcode FROM freelistings
             WHERE postcode like '%$trimmed%')         
		UNION           
	  (SELECT postcode FROM basicpackage              
	  	 WHERE postcode like '%$trimmed%')          
		UNION           
	  (SELECT postcode FROM premiumuser              
	  	 WHERE postcode like '%$trimmed%')         
	  ORDER BY postcode"; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("<b>Query:</b> $query<br><b>Error</b>: " . mysql_error());



// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

// google
echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");


// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results for $q";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row['postcode'];

  echo " $title" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< 
  Prev 10</a>&nbsp ";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
  
?>

<form method="get" action="localarea.php">
<a href="localarea.php"><?php $_POST["$q"]; 
					echo "Results for $q";?></a>
</form>

This makes no sense to me.  Why is the there a link inside a form?  What are you trying to do here?

<form method="get" action="localarea.php">

<a href="localarea.php"><?php $_POST[""" .$var. ""</p>"];

echo """ .$var. ""</p>";?></a>

</form>

This seem like an easier way to write it.

 

echo  "<a href=\"localarea.php?var=$var\">"$var"</a>";

Do you know, this was the "final peice" in my puzzle! That worked fine thank you so much for your help :D

 

Just to add i wanted to take their results from search so they can click and choose each one and it display it on a seperate page revealing other information linked to the postcode. Thanks again, thats brilliant!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.