Village Idiot is, of course, right.
I've seen this type of logic from beginners before, and its pretty understandable. What I would recommend to help you better understand what is going on is to divide up your file into two sections, one where you're doing PHP work and the other where you're outputting HTML, sort of like this:
PHP Code:
<?php
//do all your data manipulation here
$someVar = $someOtherVar;
$etc....
//then, below here you can put all your html
?>
<html>
<head>
</head>
<body>
<h1>this is an html page.</h1>
the value of a variable prepared above is <?php echo $someVar ?>.
</body>
</html>
Also, you should read a bit about how web servers work in general. The process is typically (for a php file) like:
1. a web user requests a page (
www.example.com/myPhpFile.php)
2. the server runs the php file which creates html
3. the server sends that html back to the user who requested it
4. the user's browser turns that html into a working webpage
4. the user will click something which will either request a different page, or it will send a request along with some data. The server will handle that data and then send back the resulting html again.
You'll want to send the data using forms for now
If you let us know a bit more concretely what you want to accomplish we can help a bit more
