By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Posting to a URL

P: n/a
Sorry but I have a beginners question.

(see www.freeweekends.co.uk/formask.php)

I have a form that checks for a unique id $townref of a given town

If this unique id is entered and found, I then want the associated
variables $townname and $towntitlepic passed to the url
www.freeweekends.co.uk/formreply.php

Have passed variables to a different URL within a form submit, but how
do I do this within a normal condition statement??

Code ---------------------------

<?php $townref = $_GET['town']; echo $townref; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<p align="center">&nbsp;
<p align="center">&nbsp;<font color="#FF0000">town id</font><input
type="text" name="town" size="20" value="" />&nbsp;
<input type="submit" value="GO" />
</p>
</form>
<?php
$resulttown = @mysql_query ("SELECT townname, townref, towntitlepic
FROM townid_uks49179 WHERE townref='$townref'");
while ($row = mysql_fetch_array($resulttown))
{
$townname = $row['townname'];
$townref = $row['townref'];
$towntitlepic = $row['towntitlepic'];
}
?>

<?php if (isset($GET['resulttown'])) ????????? URL formreply.php and
variables ???????
Many thanks

Alec

Jul 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alec wrote:
Sorry but I have a beginners question.

(see www.freeweekends.co.uk/formask.php)

I have a form that checks for a unique id $townref of a given town

If this unique id is entered and found, I then want the associated
variables $townname and $towntitlepic passed to the url
www.freeweekends.co.uk/formreply.php
$townname='hello';
$dest="http://www.freeweekends.co.uk/formreply.php?townname={$townname}&pic={$towntitle pic}";
$gen_output=file($dest);

(but you might want to pass the parameters thru htmlentites first).

If you really want to POST instead of GET - see the curl functions in the
manual.

C.

Jul 3 '06 #2

P: n/a
<comp.lang.php>
<Alec>
<3 Jul 2006 12:48:19 -0700>
<11**********************@p79g2000cwp.googlegroups .com>
<?php $townref = $_GET['town']; echo $townref; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<p align="center">&nbsp;
<p align="center">&nbsp;<font color="#FF0000">town id</font><input
type="text" name="town" size="20" value="" />&nbsp;
<input type="submit" value="GO" />
</p>
</form>
<?php
$resulttown = @mysql_query ("SELECT townname, townref, towntitlepic
FROM townid_uks49179 WHERE townref='$townref'");
while ($row = mysql_fetch_array($resulttown))
{
$townname = $row['townname'];
$townref = $row['townref'];
$towntitlepic = $row['towntitlepic'];
}
?>
Not sure if i understand your question correctly (even though i know it
makes perfect sense to you) and apart from that this probably isnt the
best way to do it anyway .

<?php
$resulttown = @mysql_query ("SELECT townname, townref, towntitlepic
FROM townid_uks49179 WHERE townref='$townref'");
while ($row = mysql_fetch_array($resulttown))
{
$townname = $row['townname'];
$townref = $row['townref'];
$towntitlepic = $row['towntitlepic'];
}
?>

<?php $townref = $_GET['town']; echo $townref; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<p align="center">&nbsp;
<p align="center">&nbsp;<font color="#FF0000">town id</font>
<input type="text" name="town" size="20" value="" />&nbsp;
<?php
if ($townname<>"") {print "<input type=text name=townname size=20 value=
$townname />";}
if ($townref<>"") {print "<input type=text name=townref size=20 value=
$townname />";}
if ($townpic<>"") {print "<input type=text name=townpic size=20 value=
$townpic />";}
?>
<input type="submit" value="GO" />
</p>
</form>
--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Jul 3 '06 #3

P: n/a
Krustov

Thanks for the reply, will try to better explain.

Step 1

In my database I have a list of towns each with fields for 'townname',
'townref' and 'towntitlepic'.

I have a form where the user enters a unique 'townref' number and
submits the form. The code below checks to see if this unique 'townref'
number can be found in the database, and when so then extracts the
related fields 'townname' and 'towntitlepic'.

---------------

<?php $townref = $_GET['town']; echo $townref; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<p align="center">&nbsp;
<p align="center">&nbsp;<font color="#FF0000">town id</font><input
type="text" name="town" size="20" value="" />&nbsp;
<input type="submit" value="GO" />
</p>
</form>
<?php
$resulttown = @mysql_query ("SELECT townname, townref, towntitlepic
FROM townid_uks49179 WHERE townref='$townref'");
while ($row = mysql_fetch_array($resulttown))
{
$townname = $row['townname'];
$townref = $row['townref'];
$towntitlepic = $row['towntitlepic'];
}
?>

-------------------

Step 2 - The search works OK and returns the correct 'townname' and
'towntitlepic' that relate to the entered 'townref' value in the form
(its really just a check to see if the town ref entered actually
exists)

I want to then have a condition, so if the 'townref' does exist, this
and the related 'townname' and 'towntitlepic' variables are passed to a
second page called www.freeweekends.co.uk/formanswer.php. The user has
already clicked on the form submit to do the check, so how do I pass
the variables to the new page?

Sorry because I know the answer will be really simply.

Alec

Jul 5 '06 #4

P: n/a
<comp.lang.php>
<Alec>
<5 Jul 2006 14:07:48 -0700>
<11*********************@b68g2000cwa.googlegroups. com>
<?php $townref = $_GET['town']; echo $townref; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
>
Step 2 - The search works OK and returns the correct 'townname' and
'towntitlepic' that relate to the entered 'townref' value in the form
(its really just a check to see if the town ref entered actually
exists)

I want to then have a condition, so if the 'townref' does exist, this
and the related 'townname' and 'towntitlepic' variables are passed to a
second page called www.freeweekends.co.uk/formanswer.php. The user has
already clicked on the form submit to do the check, so how do I pass
the variables to the new page?

Sorry because I know the answer will be really simply.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">

Havent tried the above - but doesnt clicking on submit take you to the
same webpage ? .
On the first page .....

<form action="formanswer.php" method="get">
<input type="text" name="towndemo" size="30">
<input type="text" name="junk" size="30">
<input type="submit" name="Submit" value="S U B M I T">
</form>

On the second page .....

<?php
$grab=$_POST['towndemo'];
$junk=$_POST['junk'];
(check town name against database)
(display results - if any)
?>

$grab will have/contain whatever text you typed into the form

$junk will have/contain whatever text you typed into the form
To sum up , Its better if you check and display on the second page .
--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Jul 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.