![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Sorry should have maked a headline: My question is still: Hey NG. Is it possible to transfer at javascript varible into at php-script? working: function ziptest() ?php ....... .... $sql = "select city from Postnr where Postnr=2720; // herafter put into mysql ? The problem is that zipcode (2720) is an javascriptvariable and should be used in a php mysql. Thought this would work - but it don't. Please help me -------------------------------------------------------------- script type="text/javascript" var postnummer = "2720"; ?php $sql1 = 'select city from Postnr where Postnr='; $sql2 = ?> document.write(bynavn) <?php $sql = $sql1 .$sql2; echo $sql; ? /script ---------------------------------------- |
#3
| |||
| |||
|
|
"Henrik Hartig" <hha (AT) scandinavianteleconsult (DOT) dk> wrote in message news:43bcfce5$0$15794$14726298 (AT) news (DOT) sunsite.dk... Sorry should have maked a headline: My question is still: Hey NG. Is it possible to transfer at javascript varible into at php-script? working: function ziptest() ?php ....... .... $sql = "select city from Postnr where Postnr=2720; // herafter put into mysql ? The problem is that zipcode (2720) is an javascriptvariable and should be used in a php mysql. Thought this would work - but it don't. Please help me -------------------------------------------------------------- script type="text/javascript" var postnummer = "2720"; ?php $sql1 = 'select city from Postnr where Postnr='; $sql2 = ?> document.write(bynavn) <?php $sql = $sql1 .$sql2; echo $sql; ? /script ---------------------------------------- My dear child, it just doesn't work that way. You've completely misunderstood how php and javascript work. You see, php is executed at the server, when the page is being generated. Then the page is sent to client, where you have the javascript. If the php was executed at the server, and the javascript at the client - in two completely different places - how do you expect javascript to pass any variables that way. It works the other way though, you can pass variables FROM php TO javascript, but not the other way around. This works: script var x = <?php echo rand() ?>; /script And why this works? Well, that's because the php was executed before the page was sent to client, therefore the client recieved script var x = 32389; // or something else /script But the other way, it's just not gonna happen. I don't know how to explain this clearer and simpler, but the thing is that you need to SUBMIT the data to the server using GET or POST, you can't pass it as a variable (unless you're using AJAX, but you're not). -- "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö spam (AT) outolempi (DOT) net | Gedoon-S @ IRCnet | rot13(xvzzb (AT) bhgbyrzcv (DOT) arg) |
![]() |
| Thread Tools | |
| Display Modes | |
| |