Post Get (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
meandrew
Forum Commoner
Posts: 49
Joined: Mon Feb 24, 2003 1:03 pm

Post Get (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY

Post by meandrew »

Please someone spot my error before I serously blow my brains out.

I have been trying to display $YouSelected and have used every possible comination. One combination displays the Value and one the same value so they are wroing trying other variables I just get nothing at all. The form posts this:


<form action='./TownsCityCompanies.php' method='POST' name='CountySearch'>

<?
require("connection.php");

mysql_connect("$DBHost", "$DBUser", "$DBPass") or
die("could not connect");
mysql_select_db("$DBName");

echo "<select name=\"CountyID\" size=\"1\" class='menuForm'>";

$result=mysql_query("SELECT County, CountyID FROM county ORDER BY County");
while ($row = mysql_fetch_array($result))
{
$county_id=$row['CountyID'];
$county=$row['County'];
echo "<option value=\"$county_id\"> $county </option>";
}
echo "</select>";

which then gets picked up in this file TownsCityCompanies.php


echo "<select name=\"CountyID\" size=\"1\" class='menuForm'>";

$result=mysql_query("SELECT County, CountyID FROM county ORDER BY County");
while ($row = mysql_fetch_array($result)) {
$county_id=$row['CountyID'];
$county=$row['County'];
echo "<option value=\"$county_id\"";
if ($CountyID == $county_id)
{echo " selected";}
echo "> $county </option>";
}
echo "</select>";

in this file it is this that is causing pain and misery :(

$alliwantis = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] :
null);

if (!is_null($alliwantis)) {

// Do some stuff


}
echo "You are in $County";

I have tried county county_id and all do everything but display the actual county name? Can anyone please spot what is wrong.

Andrew
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can access the variable you've posted as $_POST['CountyID'] or if you change the form's method to GET you can access it as $_GET['CountyID'].

Please read:
viewtopic.php?t=511

Mac
meandrew
Forum Commoner
Posts: 49
Joined: Mon Feb 24, 2003 1:03 pm

Post by meandrew »

I hope you don't think I am being stupid but it is passing a variable across! just by using

echo "You are in $CountyID";

however it is printing

You are in 1 or whatever was selected
You are in 22 etc

When I change the $ to County I get zip if I change it to county_id i get the same value regardless to what is selected. I ahve changed everytrhing except what the thing that I need to and I am exhausted with it. I was hoping that someone would spot a silly mistake but I don't think there is a mistake as ewverything works except this, unless I need to write someting that converts the value to the $County but again that doesn't make sense or does it?

Andrew
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

OK, I get the problem now, you need to do something like this on the page that processes the information from the form:

Code: Select all

$CountyID = $_POST['CountyID'];
require 'connection.php';

@mysql_connect($DBHost, $DBUser, $DBPass) or die('could not connect'); 
@mysql_select_db($DBName);

$sql = "SELECT County FROM county WHERE CountyID=$CountyID";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

$row = mysql_fetch_assoc($result);
$CountyName = $row['County'];
echo 'You selected '.$row['County'].' county.';
Mac
meandrew
Forum Commoner
Posts: 49
Joined: Mon Feb 24, 2003 1:03 pm

Post by meandrew »

I have only one thing to say you to, you are brilliant :)

That did the job I guess it was down to this?

$row = mysql_fetch_assoc($result);
$CountyName = $row['County'];

I have been trying to work out why the value and no the name was being passed for over a week so I am a happy man :)

Andrew
Post Reply