Jump to content


Photo

echo & request


  • Please log in to reply
13 replies to this topic

#1 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 28 March 2006 - 05:39 PM

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.


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 March 2006 - 05:50 PM

Does the text field (or whatever) on your form have the name='countyID' ? Note it is case-sensitive.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 28 March 2006 - 06:11 PM

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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Does the text field (or whatever) on your form have the name='countyID' ? Note it is case-sensitive.
[/quote]


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 March 2006 - 06:21 PM

Then

echo "ID is : " . $_REQUEST['countyID'];

should give --> ID is : 10

when the form is submitted
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 29 March 2006 - 04:00 AM

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.



#6 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 29 March 2006 - 04:21 AM

[!--quoteo(post=359531:date=Mar 29 2006, 02:00 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 02:00 PM) View Post[/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>)';

}




#7 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 29 March 2006 - 04:41 AM

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 :)

#8 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 29 March 2006 - 04:46 AM

[!--quoteo(post=359541:date=Mar 29 2006, 02:41 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 02:41 PM) View Post[/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']; ?><?
}
?

#9 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 29 March 2006 - 05:09 AM

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!

#10 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 29 March 2006 - 05:27 AM

[!--quoteo(post=359544:date=Mar 29 2006, 03:09 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 03:09 PM) View Post[/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:
<?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>

or 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 "<p> the city you chose was $country['title'] </p>";

}

?>


either of those usually works for me ...


#11 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 29 March 2006 - 06:24 AM

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


#12 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 29 March 2006 - 08:36 AM

[!--quoteo(post=359560:date=Mar 29 2006, 04:24 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 04:24 PM) View Post[/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.....

#13 michellephp

michellephp
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 29 March 2006 - 10:45 AM

Wow, it works!! Thanks so much :) :)

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

Thanks :D
Michelle

#14 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 29 March 2006 - 11:05 PM

[!--quoteo(post=359609:date=Mar 29 2006, 08:45 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 08:45 PM) View Post[/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......:)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users