1

I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.

I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.

HTML form header:

<form id="registrationform" name="registrationform" method="post" action="processregistration.php"> 

Submit button:

<button type="submit" value="Submit" >Create</button>

The PHP form is just <?php print "Hello"; /? Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.

Any help is appreciated.

edit-Running locally through Coda

edit-Here is the output that I'm getting:

Output when the PHP is called through an HTML action:

</php
print "Hello";
?>

Output when I run the PHP directly through Coda:

Hello 
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
prelic
  • 4,450
  • 4
  • 36
  • 46
  • What do you mean by "just run the PHP file"? Are you running it through PHP's CLI? –  Mar 16 '11 at 02:40
  • sorry, I'm using Coda, so I'm just using the Coda environment. So if I select the PHP file and hit 'preview', it executes. If I open my html file, hit 'preview' and hit 'submit', it prints the PHP code, not the output that the code should be. – prelic Mar 16 '11 at 02:43

5 Answers5

1

I had the same problem and just fixed it on my coda version 1.7.4

I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;

/Users/yourUserName/Sites

this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.

then, all you do is point the local site's connection settings to the site you are testing;

I was going to post an image, but I'm new to the site and wasn't allowed. Under my site's preferences i set up the addresses as follows;

Root URL : 'http://localhost:8888/yourSiteRootFolder/'

Local URL : 'http://localhost:8888/yourSiteRootFolder/'

Remote Root : /yourSiteRootFolder/

Local Root : /Users/amartinez/Sites/yourSiteRootFolder/

I hope this is related to the problem you're having and helps you fix it.

Alberto
  • 11
  • 1
0

Are you sure the html file and the php script are on a server with php support enabled?

Leticia Meyer
  • 167
  • 1
  • 3
  • 10
  • locally through Coda. Files are in the same folder, which I still can't forsee being the problem because it prints the PHP source file, so it's clearly getting opened, just not executed – prelic Mar 16 '11 at 02:41
  • Then why does it correctly execute when I open the file and hit 'preview'? It's obviously going through the interpreter – prelic Mar 16 '11 at 02:49
  • put this in your script: `` If it prints out a ton of info, you're good, and the php is getting executed. I don't know how Coda would be executing the php code, unless it is sending it through an installed command-line version of PHP. – Leticia Meyer Mar 16 '11 at 02:57
  • Unsurprisingly, I get the same results. When run directly, it works fine. When linked to an HTML form action, it simply prints the source of the PHP file. – prelic Mar 16 '11 at 02:59
  • Coda must be executing the php and putting the output into its preview section. If you want it to work linked from an html form, you're going to have to install some form of a server and php. Mac OS X already has both pre-installed, you just have to enable them: http://www.devarticles.com/c/a/Apache/Using-Apache-and-PHP-on-Mac-OS-X/ – Leticia Meyer Mar 16 '11 at 03:07
0

I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.

Try looking at xampp as a quick server for testing. If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.

  • If that was the case, then why would it run when I open the file and hit 'preview', which is Coda's version of run/execute. If I couldn't get it to run at all, that'd be different. If I call it through an HTML file, it doesn't work. If I run it directly through Coda (preview), it runs fine – prelic Mar 16 '11 at 02:53
  • Coda's preview probably only runs it temporarily for the preview (perhaps Coda runs `php myfile.php`), and only executes when you specifically want it to. –  Mar 16 '11 at 02:56
0

Line #19 from Coda 1.6 Release notes:

Coda no longer tries to locally preview a remote PHP file while editing/previewing

Listed under "Improvement" - doubt they brought it back for the 1.7 release.

I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda) Even when running my form.html and post.php files from /Library/WebServer/Documents folder.

My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)

Dawson
  • 7,567
  • 1
  • 26
  • 25
  • My guess is that Coda is now previewing PHP files just as any other browser would preview them out of a server environment. It's def not using Apache (present or not) per my experience above. – Dawson Mar 16 '11 at 03:44
  • Thanks so much...so it's not possible to make this work in Coda? And I should just run them in the Apache environment? – prelic Mar 16 '11 at 03:46
  • Absolutely - I'm sure you'll find some scenarios where a quick preview via PHP will do the trick. It just won't work for every situation. – Dawson Mar 16 '11 at 03:48
  • Thanks, I put the same code into my web folder, and it ran without a problem...never would've figured that out. – prelic Mar 18 '11 at 01:15
-1

This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.

Here are some resources to get you started with that, if not installed:

http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp

Edit: actually, I think I may have found it.

If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.
Tanner Ottinger
  • 2,970
  • 4
  • 22
  • 28
  • Again, I would agree if that's all it did when I ran it directly (not through the HTML), but it does. It correctly executes when I run it directly through Coda, but not when I call it indirectly through an HTML file (still through Coda) – prelic Mar 16 '11 at 02:51
  • So it's displaying the code that supposed to print text? If so, I would install Wamp Server, and test you code there. Then you would have better tracking capabilities. – Tanner Ottinger Mar 16 '11 at 02:52
  • Correct, I'm on a Mac, using Coda, an OSX-only application. I very much doubt the problem is my environment if I can get the code to run, which I can, just not when I use the HTML action. – prelic Mar 16 '11 at 02:57
  • I really don't know how to help, as I have never had this kind of problem before. But XAMPP does have a mac dist. Also, maybe you should try running this code without Coda. – Tanner Ottinger Mar 16 '11 at 02:59