Running PHP with WAMP
Posted by: npcs (78.133.37.---)
Date: December 19, 2009 09:17PM

Hi all,

I have just installed WAMP, but every time I try to open a PHP file in browser, it is just writing the PHP code, rather than running the script. The only time it works is if I save the PHP to index.php, and open localhost.

Can anyone help me understand why this is going wrong?

Regards,

Neil Sammut

Re: Running PHP with WAMP
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 19, 2009 09:25PM

thats how its supposed to be
u have to run in thru the browser

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Re: Running PHP with WAMP
Posted by: npcs (78.133.37.---)
Date: December 19, 2009 09:27PM

And how are you meant to do that, if I might ask?

Re: Running PHP with WAMP
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 19, 2009 10:30PM

put the files into the www folder...
then use http:/ /localhost/filename.php

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Re: Running PHP with WAMP
Posted by: npcs (78.133.37.---)
Date: December 19, 2009 10:39PM

What I am trying to do is use a JavaScript function (embedded in an HTML page in www folder) to read from a php web service (php file in the same www folder).

It keeps returning the code, rather than the result..

Re: Running PHP with WAMP
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 19, 2009 10:44PM

whats a php web service?

make sure ur file is called .php and make sure u have <?php instead of <?


all the files shud be in the www and all shud be run thru localhost


php is a serverside scripting language and must compile itself and then send to the browser

otherwise ul just get php code output

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Re: Running PHP with WAMP
Posted by: npcs (78.133.37.---)
Date: December 19, 2009 10:46PM

I suppose I should show you my code..



CLIENT:

<html>
<head>
<title>AJAX in your web page</title>
<style>
#result { background-color: #DDDDFF;}
</style>
<script type=text/javascript language=javascript>
<!-- Hide Javascript on old browsers

var rqo;

function aboutlang(current) {
var lang = current.options[current.selectedIndex].value;

if (lang != ""winking smiley {
document.getElementById("result"winking smiley.innerHTML =
"Fetching data ... <br /><br /><b>" + lang + "</b>";

rqo = new XMLHttpRequest();
var qs = encodeURIComponent(lang);
var qry = "index.php?towhich=" + qs;
rqo.open('GET',qry,true);
rqo.send(null);

rqo.onreadystatechange = handlelang;

}
return false;

}

function handlelang() {
document.getElementById("result"winking smiley.innerHTML =
rqo.responseText + " (via Ajax)";

}
-->
</script>
</head>
<body>
<h1>Ajax demonstration - Asynchronous Javascript and XML</h1>
The selection box on this page calls up a server side program
(an application server / content provider / web service) and
displays elements of the result in the changeable area of the page
<hr />
<form>Please select a programming language
<select onChange="aboutlang(this)">
<option value="None">------</option>
<option value="Perl">Perl</option>
<option value="PHP">PHP</option>
<option value="Python">Python</option>
</select>
<input type="submit" value="Reload page / Reset"/>
</form>



SERVER:


<?php

/* Ajax Demonstration - takes "towhich" parameter and looks up
that string in an array of possible responses */

$responses = array(
"Perl" => "Perl was written by Larry Wall",
"PHP" => "Rasmus Lerdorf wrote PHP",
"Python" => "From Guido van Rossum came Python"winking smiley;

$send = $responses[$_REQUEST[towhich]];
if ($send == ""winking smiley {
$send = " --- No information available --- ";
}

$send = "Data retrieved from server at ".date("H:i:s"winking smiley.
" server time<br /><br />"."<b>$send</b>";

print ($send);
?>



Any ideas..?

Sorry, only registered users may post in this forum.