View Full Version : POST & GET question

06-26-2005, 06:51 PM
Hi and thx for a great forum!

Im having some trouble with sending data from one page to another!

I have a textfield and a submit-button. When clicking on the button the text in the textfield should be sent to another page where it is implemented into a search-function.

Simple: I wan't the text in the textfield to be sent to another page. How is this easily done? I want the text to be saved in $sok which shall be used in this manner...

$asking = "SELECT namn, tillverkare, pris, vikt FROM artiklar WHERE namn = $sok";

06-26-2005, 07:00 PM
$sok = $_POST['textfield_name'];

06-26-2005, 07:12 PM
Since I still don't clearly understand...here are some more code. Sorry to bother!

<form name="form1" method="post" action="">
<input name="searchfield" type="text" size="50" maxlength="30">
<input name="namn" type="radio" value="1">
<span class="style2">Namn
<input name="vikt" type="radio" value="2">
<input name="tillverkare" type="radio" value="3">
<input name="pris" type="radio" value="4">
<input type="submit" name="Submit" value="S&ouml;k varor">
<input name="clear" type="reset" id="clear" value="Rensa">
include 'functions.php';
if (isset($namn)) {
elseif (isset($vikt)) {
elseif (isset($tillverkare)) {
elseif (isset($pris)) {
echo ("Välj ett alternativ ovan innan du söker.");

The textfield has the namne searchfield and when clicking on the button the text in that field should be usable in some functions on another page, functions.php.

function namn_search() {
$sok = $_GET['searchfield'];
$db = @mysql_connect("localhost","root","")
or die("Kunde inte komma åt databasen!");
$databasen = mysql_select_db("matlistan");
echo "Alla varor i med<b></b>. Om ej vikt anges är priset ett kg-pris.";
$asking = "SELECT namn, tillverkare, pris, vikt FROM artiklar WHERE namn = $sok";
$resultat = mysql_query($asking);

<table borde="1" cellspacing="5" cellpadding="5" align="center">
<th><?=mysql_field_name($resultat, 0);?></th>
<th><?=mysql_field_name($resultat, 3);?></th>
<th><?=mysql_field_name($resultat, 1);?></th>
<th><?=mysql_field_name($resultat, 2);?></th>
while ($raden = mysql_fetch_row($resultat))
echo "<tr><td>$raden[0]</td><td>$raden[3]</td><td>$raden[1]</td><td>$raden[2]</td></tr>";

06-26-2005, 07:27 PM
You're sending the form via POST, so

$sok = $_GET['searchfield'];

Won't work, it'll need to be

$sok = $_POST['searchfield'];

Also, you need to change

if (isset($namn)) {


if (isset($_POST['namn'])) {

Do the same with the rest

06-26-2005, 07:31 PM
Excellent, that did the trick. Thank you very much for this.

Best regards

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum