/    Sign up×
Community /Pin to ProfileBookmark

How do I invoke PHP in a webpage?

I am trying PHP for the first time, so be kind. I have just spent several hours browsing various tutorials and this forum, and can’t find how to actually get my PHP script to run. I checked my site’s host server, and it does support PHP.

The example I’m using (from a manual) says to put this in my webpage:
<?php include (“sidemenu.html”); ?>
and it is supposed to copy sidemenu.html into the webpage. It doesn’t work. I also tried renaming the file sidemenu.shtml (suggested in one of the forums) and using <?php include (“sidemenu.html”); ?> This doesn’t work either.

I then tried placing the code in a file named sidemenu.php and adding this to the webpage:
<script type=”text/php” language=”php” src=”sidemenu.php”></script>
Still doesn’t work.

I think my problem is the PHP script is never invoked. I’m guessing I need to do something similar to what I do to get my JavaScript routines to run, but I can’t figure out the syntax to use with PHP. All my JavaScript routines run onClick, I want the PHP to run when the page is built (no user action required).
<input type=”submit” value=” Submit ” name=submit onClick=”ValidateSOForm(this.form); return ValidReturn;”>

Can anyone help me?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyOct 19.2006 — The file with PHP in it needs to be called filename.php, then just access it from a browser.
Copy linkTweet thisAlerts:
@elaurvickauthorOct 19.2006 — sidemenu.php has the PHP script in it. Please give me an example of how to "just access it from a browser". That's what I can't figure out how to do, and I can't find any sample code.
Copy linkTweet thisAlerts:
@sitehatcheryOct 19.2006 — To clarify, you don't have to include filename.php. I think bathurst_guy means the to say the script that has the include function must have a php extension. You can include filename.html, htm, shtml, etc. Test this and you will see that it works.

elaurvick... have you verified that the files have been uploaded to the server? Also some hosts display a blank screen if there are errors in the script. So, you may have an error in your included file or in the script calling sidemenu.php.
Copy linkTweet thisAlerts:
@SheldonOct 19.2006 — Also i dont no if you go it, but you but the include statement not in to the file you want to include, but in the file that includes it.

eg:

index.[B]php[/B]
[code=php]
<html>
<head>
<title></title>
</head>
<h1>TITLE</h1>
<?php include("sidemenu.html"); ?>

Content
Content
</body>
</html>
[/code]


sidemeny does not have to have a php extension, but does if it is going to run a PHP script in the menu.
Copy linkTweet thisAlerts:
@Mr_Initial_ManOct 19.2006 — OKay, a couple questions we seem to be dancing around.

[list=1]
  • [*]Is this page on 1) your computer or 2) on a website host?

  • [*]If it's on your computer, does your computer have the Apache server or something similar installed?

  • [*]If it does have Apache, are you running your file through it? If your browser mentions a drive letter (most likely C: if you're using windows), you're not running it through Apache. If you're using a "localhost" address, everything should be fine.

  • [*]If you're running it off a server, does the server support PHP?

  • [/list]


    Just a couple things to consider.
    Copy linkTweet thisAlerts:
    @elaurvickauthorOct 21.2006 — I finally got it. I had the .php extension on the wrong file.

    testpage.php includes sidemenu.html perfectly, and the links in sidemenu work.

    Thanks to you all!
    Copy linkTweet thisAlerts:
    @chadillacNov 20.2006 — [CODE]
    <?php

    info();

    ?>
    [/CODE]


    the ultimate newbie debug
    ×

    Success!

    Help @elaurvick spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...