How to get your PHP program to work
- Use jEdit (or any other color-coding text editor) to write your
program. Color-coding help you catch mistakes such as a mistyped
keyword or a non-closing quotation mark.
- Don't write a program all at once, write a little bit at
a time. Test your program every time you change or add
something.
- To test, upload your file to your public_html (or its subfolder)
on
rynite. Type the URL in the browser. If you get a file-not-found
error, double-check the file name, its location, and the
URL. Remember that you
don't include public_html in the URL. For instance, if your file is
prob1.php
in the folder probset2
in your
public_html
, and
your user name is smithj
, the URL would be:
http://rynite.morris.umn.edu/~smithj/probset2/prob1.php
- If the program works, but the result is not what you expected,
look at the html source. The source is generated by your php program,
so you can catch mistakes in the program's logic. For instance, you
may be opening a <td> tag in a loop but closing it outside the
loop, so there will be multiple opening tags and only one closing
tag.
If the html looks OK to you but the page doesn't look right,
run it through the XHTML
validator. Sometimes you may not see subtle errors but the validator
will show them to you.
- If the result is not what you expected and you don't immediately
see a mistake, you can try to run the program directly on the server
in a hope that you get some helpful information from the error
messages:
- login to rynite using
ssh
:
- In the lab type
ssh
rynite
(or ssh yourusername@rynite
if
your user name is different on rynite) in the terminal window. Enter
the password.
- On your home machine (Windows) you can install
putty
- a simple program that allows you to connect to a server via ssh. If
you are off campus, type rynite.morris.umn.edu
for the
host name.
- If
you have a Mac, you should be able to use ssh in the command prompt
window, just like you do in the lab (but use
rynite.morris.umn.edu
instead of just rynite
if you are off campus).
- Change the directory to where your file is located using
cd
command, for instance cd
public_html/probset2
.
- Type
php myfile.php
(where instead of
myfile.php
you use the actual file name). This will give
the HTML output of the program (if any) and error messages (if
any). Some error messages are not very clear, but they usually give
you at least some idea of what's wrong and point to a specific line in
your program where the mistake was detected (note that the actual
mistake may be earlier, for instance a forgotten semicolon will be
detected on the next line).
Unfortunately you cannot pass the input values this way so they are
considered zeros for numbers and empty strings for strings.
- Correct the mistake in jEdit and upload your file again.
-
If a program does not seem to change no matter what you do, chances
are you are uploading files into a wrong location. Put a print
statement in the very beginning of your php code. If it doesn't show
up on the page, check the file location.