Forum Moderators: coopster

Message Too Old, No Replies

Newbie PHP & MySQL: include & testing server

Include command not working, is server set up correctly?

         

picophd

2:15 am on Nov 15, 2004 (gmt 0)

10+ Year Member



Hello,

I'm a pure newbie in PHP and MySQL, with very good knowledge in HTML and CSS, using Dreamweaver MX 2004 to code.

I just installed MySQL 4.1, and chose C:\MySQL Datafiles\ as the server folder (not the installation folder). And now I have a PHP testing and learning site set up in Dreamweaver with site local root folder as:

C:\PHP\

And the Testing Server details are:

  • Server model:
    PHP MySQL

  • Access:
    Local/Network

  • Testing server folder:
    C:\MySQL Datafiles\

  • URL prefix:
    file:///C:/PHP/
    (and it says that the URL Prefix is the location of the site's root folder on the testing server)

    The code inside a testing.php file is:


    <html>
    <head>
    <title><?echo $title?></title>
    </head>

    <body>

    <?php include "email.txt";?>

    </body>
    </html>


    I have an email.txt file with some (hello world) in it, in both: (MySQL Datafiles) folder, and (PHP) folder.

    Now when I test the testing.php file in the browser, I do not see the contents of the email.txt file in the page. :(

    Why is that? It's obvious I'm doing something wrong. Maybe I have setup the server in the wrong way? Or I gave Dreamweaver the wrong paths in the Testing Server details?

    Thanks a lot for anyone taking the time to help.

  • baertyp

    8:09 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    The include()d file has to be valid php code, otherwise you will get an error.

    <?php phpinfo();?>
    will show you your current path settings.

    Regards
    Markus

    picophd

    10:18 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Isn't this a valid PHP code:


    <html>
    <head>
    <title><?echo $title?></title>
    </head>

    <body>

    <h1>
    Hello World!
    </h1>
    <p>
    Hello again, World!
    </p>

    </body>
    </html>


    Isn't any simple text in a txt file valid PHP code? Before reading your post, I simply had "hello world" inside an email.txt file. But after reading your post, I changed the file to email.php, and wrote in it the code above. It still didn't work.

    I also pasted the line that you gave me inside the testing.php file, but nothing showed up at all in the browser after testing the page. :(

    I think I'm doing something else that is wrong. How can I be sure that MySQL 4.1 server (essential version) is running correctly to run PHP files correctly? And how do I setup the PHP website locally using Dreamweaver? The information I posted in my last post has details about the information that Dreamweaver needs. Did I give Dreamweaver the info correctly?

    ukgimp

    10:30 am on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    You main objective imho is finding out if you have php running and ready for action

    so try the phpinfo as suggested

    <?php
    phpinfo();
    ?>

    If you get a big blue screen with loads of info on it you are cooking.

    to test for printin variables dont bother with using includes as the moment, they can cause their own problems with paths etc

    Try this

    <?php
    $printing_var = "This mutha works";

    //print the Variable to the screen
    print "<h1>$printing_var</h1>";

    ?>

    Make sure you have the server running and try and request the page, if you see big fat letters on the screen, smile :)

    HTH a little

    picophd

    10:39 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Ok, I'm sorry I have to be THIS newbie. But what do you mean "PHP running"? I thought that this is a scripting/programming language for developing databases, interactive web pages, and a bit of web applications, and that in order for me to test PHP pages, I have to have a server like MySQL installed, which I did.

    What else do I have to install exactly so that PHP is "running"? I only have graphic design, loads of WYSIWYG stuff, and I use Dreamweaver to code, plus MySQL 4.1 (essential version) installed on my PC. But that's it. Nothing specifically for PHP.

    How do I start cooking, man? :)

    pete_m

    10:44 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    It looks like you're trying to access the files directly through the filesystem, rather than through a web server. I don't use Dreamweaver, but setting the URL prefix as
    file:///C:/PHP/

    looks suspicious. It should look something like:
    http://localhost/PHP/

    You need to set up a webserver - either Apache, IIS or PWS - on your development machine. You then access the page through the web server, so that the php pages are be parsed and executed.

    At the moment you're just viewing the file testing.php - I'm guessing that when you do a "View Source" in your browser, you see exactly the contents of the file, including the PHP code.

    ukgimp

    10:49 am on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    you running this on a windows box?

    If yes and you want an apache server up and running, think about downloading phpdev (firepages.com.au). Double click and you have an apache server with php, mysql etc running in 5 minutes.

    Compiling it yourself will be no fun my friend :)

    picophd

    11:07 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Guys, are you telling me that PHP and MySQL are not enough together? I was hoping to limit the stuff I learn, for now, to open source things. Heck, I can't wait until the day I give up my "good ol'" Windows for Linux. From what I know, most web servers out there are commercial, but MySQL is open source and free.

    Besides, I keep hearing "PHP & MySQL" a lot. I mean both come together a lot. I thought these guys were buddies. I'm a bit lost, but I'm really eager to understand. Will you tell me why I need Apache or Microsoft's IIS and not MySQL?

    ukgimp

    11:25 am on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    IIS = Server technology lumped with windows

    Apache = Open source server tech

    Typically you will find that hosts who run apache have all the open source stuff available as well. So you will find the database stuff (mysql) and the web langauge (PHP) ready to go.

    If you want to emulate an apache environment on a windows machine with little effort, consider that firepages i recommend. You can do most of what you will find on a dedicated apache server (httpd edit etc) without working out how to compile it.

    You can run php on an IIS server, but that is not typical and less than easy imho.

    picophd

    11:49 am on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Ok, what about these Windows Binaries files they have avaiable for download in php.net? What do you need those for? Again, my understanding that PHP is a scripting language, which I can type using even a Notepad, just like HTML, with the huge difference in power and capabilities, of course. But I thought that just like I don't need to install anything called "HTML" in order to write HTML, I also didn't need to install anything called "PHP" to write PHP.

    Again, I'm using Dreamweaver to write the code. And now I understand that I need a web server technology installed on my system, like IIS or Apache (although I still don't understand why MySQL does not suffice). However, what about these Windows Binaries files in php.net, now?

    ukgimp

    12:03 pm on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    MySQL is like access, it a database that come with apache installations.

    It is not an easy area to follow if you are not that sure. I can stress how easy a pre-compiled application liek the one i recommend. You will see how they all fit together.

    No offense but you have a long road ahead if you try and intall these things manually if you are not sure how the different bits fit together.

    you can learn how to do proper installs later if needs be.

    coho75

    12:08 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    But I thought that just like I don't need to install anything called "HTML" in order to write HTML, I also didn't need to install anything called "PHP" to write PHP.

    You don't need anything installed called "PHP" to write PHp. You are right that PHP code can be written in Notepad or any other such utility. However, to see the PHP in action on your own machine, you need to install PHP along with Apache. Just like HTML, without a browser you would not see anything but a text file. The browser interprets the HTML and thus you see a web page.

    MySQL is the database part of the equation, it does not interpret the PHP code, it simply stores values.

    Hope this helps clear a few things up.

    picophd

    12:42 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    ukgimp, I didn't take offense at all, mate. Heck, I KNOW I have a long way to go. :) All I hope is that patient folks like all you guys will find my posts and demystify these things for me at least a little bit, so I can walk down the road of server-side scripting at least knowing how to read the signs. Thanks a million for recommending the download from the .au site. I read what the guy had to say there about phpdev and what it is, and it sounded like exactly the thing I need for now!

    coho75, ohh yes, that did clear up important things for me. Thank you very much really! :)

    I got a few questions, though, HOPEFULLY the last in this topic. You said MySQL stores values, because it's just the database part of the equation.

    Now do you mean that MySQL is where I store PHP "variables", for instance?

    And in an example like:


    <html>
    <head>
    <title><?echo $title?></title>
    </head>
    </html>


    ...where exactly do I store the $title value? Given that I installed MySQL 4.1 last night, and--God willing--I'm installing phpdev423 now?

    Are the PHP Windows Binaries from php.net, and phpdev423, the same, then, but phpdev423 is easier? So if I install phpdev423, then I don't need to install those Windows Binaries files from php.net?

    picophd

    2:27 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    IT'S ALIVE!

    It worked. I'm cooking! :)

    I installed phpdev, and thankfully, after a few trials, figured how to put my testing/learning website on my computer, and I tested it, and it worked. It looked so beautiful coming from my PC after I could only see that stuff on my website host. :)

    Thank you again, ukgimp.

    Now pleease, I just want to know this one thing: how do I assign a value for a variable like $title OUTSIDE the php file itself which has this title?

    I read about the 2 kinds of PHP symbol tables: global and function-local, where you store a list of variable names and their values. Now how do I code or develop a symbol table like that? I don't want a table with hundreds of fields, just 2 variables, for instance, for training and learning. And how do I make a php file get the values of the variables in it from that symbol table? Is there a way like linking? Like when an HTML file is linked to a CSS file to get its style data from it?

    ukgimp

    2:48 pm on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    You need two files

    <?php

    include('includes.php');

    print "$title";

    ?>

    the create a file in the same directory called include.php

    and have the following

    <?

    //file variables

    $title = "My site Title";

    ?>

    Now when you view the first file it inlcuded the second which allows you to use that varaible. So if you have 1000 pages on your site you only need to change the inlcude file to change all the pages.

    Is that what you were asking

    picophd

    3:16 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Yes, exactly! :)

    Again, thank you, ukgimp.

    How do I display that title in the Title Bar? I mean what do I put inside the <title> tag?

    That's it for this topic. Thank you all so much, and thanks to you, ukgimp.

    Slade

    3:30 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Your example from before was very close to what is probably being expected by your current config. Change it to:

    <html>
    <head>
    <title><?php echo $title;?></title>
    </head>
    </html>

    [edited by: Slade at 3:32 pm (utc) on Nov. 15, 2004]

    ukgimp

    3:32 pm on Nov 15, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Tutorials my friend, lots of em about

    [w3schools.com...]
    [freewebmasterhelp.com...]

    picophd

    3:58 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Yes, I figured it out, I swear. That's what I did and kept testing it, but the title just wouldn't show.

    What I did NOT know, was that I have to put the:


    <?php

    include('varvalues.php');

    ?>


    part BEFORE the <title><?php echo $title;?></title> part.

    Having just immigrated from HTML coding, I thought that everything has to go in the <body></body>, you digging me? :)

    But I figured it out. There's still hope in me, I'm not THAT dumb. Hehehe. :)

    Thank you

    coopster

    4:17 pm on Nov 15, 2004 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    picophd, you may also want to try this thread for some ideas Learning PHP - Books, Tutorials and Online Resources [webmasterworld.com]

    picophd

    4:43 pm on Nov 15, 2004 (gmt 0)

    10+ Year Member



    Thanks a bunch, coopster.

    Sorry if I sounded like I don't want to study on my own. It's just that technical authors can sometimes confuse, rather than make you feel welcome. Also, sometimes I have questions about something that is not working, and I keep looking for answers online, but can't find any. So I end up needing to ask, and repeatedly. :)