Hello Everyone
I'm pretty new to php, been doing web pages for a little while...
I have understood all that I have learnt so far (using lynda.com PHP training title). I am building a personal website to test all the concepts I learnt in the DVD, and am currently up to creating my blog with the usual PHP/MySQL combination to manage the articles.
I built a form for my admin area to store stuff like the title, contents, article, resources etc. and created an appropriate table to archive the data.
I then wrote an include connection file as follows:
<?php
$dbHostname = "localhost";
$dbUsername = "root";
$dbPassword = "######";
$dbName = "#######_website";
// Make connection to database
// If no connection made, display error Message
$dblink = MYSQL_CONNECT($dbHostname, $dbUsername, $dbPassword)
or die("Error !! Unable to connect to database");
echo '<b>Step 1:</b> Connected successfully! <BR>';
// Select database or print error message if unsuccessful */
mysql_select_db($dbName) or die( "Unable to select database ".$dbName);
echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>';
?>
As you can see I have put in the echoes to let my self know if I have connected successfully to mysql and then if I have connected to the database.
Testing this file produced something very unexpected and has tipped me off to the fact their must be some bigger problem, possibly with php or mysql or wamp configurations.
What happened first was that step 1 reported succesful completion, however the next lines of code simply displayed raw in the browser (firefox) like this
Step 1: Connected successfully!
'; // Select database or print error message if unsuccessful
mysql_select_db($dbName) or die( "Unable to select database ".$dbName);
echo 'Step 2: Connected to ('.$db.') successful!
'; ?>
Both IE and safari displayed the whole file raw (and yes the file has a .php ext)
What is going on??
I thought I would try and locate the bug by removing any code that wasn't essential and re-testing. When I removed the echo after step 1, step two reported successful?!!?? (in firefox) but the closing php bracket shows up along with the semicolon from the line before, like this...
Step 2: Connected to ('.$db.') successful!
'; ?>
So I assume by logic step 1 has to have worked and step 2 proceeds now the echo for step 1 is gone.
I tested with an example connection file as well (modyfying it with the details of my db) and the same problem happened, suggesting it is something global.
As stated before IE and safari are simply not displaying processed code at all, and firefox is doing this partial business as explained.
Also why is the echo playing a role?
HELP please!!
I have made excellent in roads in the last couple of weeks to learning PHP and I don't want this small thing to discourage me. I have been stuck at this point for 6 days :queasy:
Anyone who could take me through the possible problems would be GREATLY appreciated.
Thanks
-DrTim