Jump to content

echo & request


michellephp

Recommended Posts

Hello again!

I was just hoping someone could tell me how to have a value that has been inputted into a form. eg

house.php?countyID=10

echoed in the body somewhere?

I think it has to do with $_REQUEST['countyID'] but I can't get it to work.


The second part of the problem is, the countyID number has a corresponding name, eg Sydney. (countyID=10 =Sydney). That info is in the database... how do I convert the number into the name?

Extra info:

This has worked on another page of my site, but I can't get it to work on the search page. Here's the bit from the other page:

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());
$county = mysql_fetch_assoc($R);

AND

<? echo $county['title']; ?>



Thank-you :)
Michelle.
Link to comment
Share on other sites

hi

yes it does :)

[!--quoteo(post=359368:date=Mar 28 2006, 12:50 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 28 2006, 12:50 PM) [snapback]359368[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Does the text field (or whatever) on your form have the name='countyID' ? Note it is case-sensitive.
[/quote]
Link to comment
Share on other sites

Hi Barand,

Thanks for that :) So now I have the id number displaying (eg 10). Do you know how I can change that into the correspong title, eg Sydney?

I tried: <? echo $county['title']; ?>

But i think I need to fetch the info for the county first. But like I said, the code:

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());
$county = mysql_fetch_assoc($R);


Just causes an error. Any ideas?

Thanks again!
Michelle.

Link to comment
Share on other sites

[!--quoteo(post=359531:date=Mar 29 2006, 02:00 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 02:00 PM) [snapback]359531[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi Barand,

Thanks for that :) So now I have the id number displaying (eg 10). Do you know how I can change that into the correspong title, eg Sydney?

I tried: <? echo $county['title']; ?>

But i think I need to fetch the info for the county first. But like I said, the code:

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());
$county = mysql_fetch_assoc($R);
Just causes an error. Any ideas?

Thanks again!
Michelle.
[/quote]

can you put it through a while loop and then display it?:

while ($country = mysql_fetch_assoc($R)) {

echo('<p>the city you requested is $country['title'] <p>)';

}


Link to comment
Share on other sites

hi!

Do you mean leave the:

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());
$county = mysql_fetch_assoc($R);


in? Because I always seem to get this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

But when I take it out and put this in:
<? while ($county = mysql_fetch_assoc($R)) { ?>
<? echo $county['title']; ?><?
}
?>

I get: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/homebuy/public_html/towns.php on line 66

Thanks :)
Link to comment
Share on other sites

[!--quoteo(post=359541:date=Mar 29 2006, 02:41 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 02:41 PM) [snapback]359541[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hi!

Do you mean leave the:

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());
$county = mysql_fetch_assoc($R);
in? Because I always seem to get this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

But when I take it out and put this in:
<? while ($county = mysql_fetch_assoc($R)) { ?>
<? echo $county['title']; ?><?
}
?>

I get: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/homebuy/public_html/towns.php on line 66

Thanks :)
[/quote]

try:

<? while ($county = mysql_fetch_array($R)) { ?>
<? echo $county['title']; ?><?
}
?
Link to comment
Share on other sites

[!--quoteo(post=359544:date=Mar 29 2006, 03:09 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 03:09 PM) [snapback]359544[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I get:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/homebuy/public_html/towns.php on line 69

:( I don't get it!
[/quote]

so does you code look like this:
[code]<?php

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());

$country = mysql_fetch_array($R) //and this is line 69? or try mysql_fetch_assoc($R);

$city = $country['title'];

?>

<p>the city you chose was <?= $city ?></p>[/code]

or this:

[code]<?php

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());

while ($country = mysql_fetch_array($R))  { //and this is line 69? or try mysql_fetch_assoc($R);

echo "<p> the city you chose was $country['title'] </p>";

}

?>[/code]


either of those usually works for me ...
Link to comment
Share on other sites

For the first one I got: Parse error: syntax error, unexpected T_VARIABLE in /home/homebuy/public_html/towns.php on line 77

and for the second i got:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/homebuy/public_html/towns.php on line 77

and for this:
<?php

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());

while ($country = mysql_fetch_array($R)) { //and this is line 69? or try mysql_fetch_assoc($R);

echo $country['title'];

}

?>

I get: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Link to comment
Share on other sites

[!--quoteo(post=359560:date=Mar 29 2006, 04:24 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 04:24 PM) [snapback]359560[/snapback][/div][div class=\'quotemain\'][!--quotec--]
For the first one I got: Parse error: syntax error, unexpected T_VARIABLE in /home/homebuy/public_html/towns.php on line 77

and for the second i got:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/homebuy/public_html/towns.php on line 77

and for this:
<?php

//fetch details for county
$sql = 'select * from counties where id = '.$_REQUEST['CountyID'];
$R = mysql_query($sql,$myconn) or die(mysql_error());

while ($country = mysql_fetch_array($R)) { //and this is line 69? or try mysql_fetch_assoc($R);

echo $country['title'];

}

?>

I get: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
[/quote]

there's an error on this line of the first one:

$country = mysql_fetch_array($R) - the semi colon is missing from the end of the line.....!!!!

it should be:

$country = mysql_fetch_array($R);

for the second one try:

while ($country = mysql_fetch_array($R)) { //or try mysql_fetch_assoc($R);

echo "<p>you chose " . $country['title'] . "</p>";

}

if these don't work then when you post the error message please post the line from the code where the error is....:)

by the way is register_globals = On in your php.ini file...... if not and you can access the file find the entry f register_globals = Off and change it to on. save the file and restart your webserver.....
Link to comment
Share on other sites

[!--quoteo(post=359609:date=Mar 29 2006, 08:45 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 08:45 PM) [snapback]359609[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Wow, it works!! Thanks so much :) :)

I used the second one, the first would still not work.

Thanks :D
Michelle
[/quote]

no worries, I'm learning myself so i know how frustrating this can be......:)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.