andy_b_1502 Posted October 15, 2011 Share Posted October 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/ Share on other sites More sharing options...
Pikachu2000 Posted October 15, 2011 Share Posted October 15, 2011 It really isn't clear what you're trying to make that code to do with the html entities scattered in it and what-not. Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279596 Share on other sites More sharing options...
andy_b_1502 Posted October 15, 2011 Author Share Posted October 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279598 Share on other sites More sharing options...
andy_b_1502 Posted October 15, 2011 Author Share Posted October 15, 2011 And then on the target page use: <?php print_r($_GET);?> Or something to display the users result etc[/code] Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279599 Share on other sites More sharing options...
andy_b_1502 Posted October 15, 2011 Author Share Posted October 15, 2011 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>  "; } // 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> Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279603 Share on other sites More sharing options...
Drummin Posted October 15, 2011 Share Posted October 15, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279610 Share on other sites More sharing options...
andy_b_1502 Posted October 15, 2011 Author Share Posted October 15, 2011 Do you know, this was the "final peice" in my puzzle! That worked fine thank you so much for your help 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!! Quote Link to comment https://forums.phpfreaks.com/topic/249177-help-needed-with-get-and-post/#findComment-1279613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.