SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Connecting to localhost

    Hi all

    Following a Sitepoint PHP book. Have written a few scripts that I want to test locally (MySQL database hosted on machine locally also) but when I try to get to a page I have created in the browser it doesn't work, I can see all the code on the page. What URL do I need to give to be able to access a functioning PHP page. I have tried: h_t_t_p://localhost:8080/location ...
    But it says "The connection was refused when attempting to contact localhost:8080".

    Can someone help please? Sure it's something obvious ...

    Thanks

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Hi Sussextech and welcome to SitePoint

    A couple of things to check first ;

    Is PHP running?
    Is MySql running?
    what if you go to: http://localhost/
    where is your root folder when you installed apache or IIS?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Soikez - thanks for the warm welcome!

    Followed h_t_t_p://localhost/ and it came up with a PHP script that calls the date from IIS. This must mean that things are working! I have been playing with MySQL through the console so I know that is also on.

    Should I place all the files into the localhost folder for IIS? This makes perfect logical sense to me now, but I wanted to check!!!

    Thanks again

    ST

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    OK well that means that PHP and IIS are both running which is a great start (saves an awful lot of problems!)

    Any file you want parsing by IIS and displayed to the browser would need to be in the root folder - localhost.
    You can create folders inside that root eg: an images or a project folder which you can navigate to: http://localhost/project

    To fully test the PHP installation, create a file called info.php and in it add the following line of code:

    PHP Code:
    <?php php_info(); ?
    Then navigate to it and see what is generated .
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP list thing comes up, like it does when testing after installation.

    By the way: Followed your instructions, placed into the localhost folder after some debugging, and now it shows nothing but a blank page!!! lol

    Thanks! ST

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    lol, well we are getting there!

    What code do you have on your page (not the phpinfo page)?

    Post it up. it might be your error reporting levels are set very low - so they dont give any error messages. You will need to locate your php.ini file and check the error_reporting setting.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol here it is (From a sitepoint book):

    Code:
    <?php if (isset ($_GET['addjoke'])): // user wants to add a joke ?>
    
    <form action="<?php echo $_SERVER[’PHP_SELF’]; ?>” method="post">
    <label>Post your stuff here: <br />
    <textarea name=”joketext” rows=”10” cols=”40”>
    </textarea>
    </label><br />
    <input type=”submit” value=”SUBMIT” />
    </form>
    
    <?php else:
    
    //default page display
    //connect to the database server
    
    $dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘arcanum1’);
    if (!$dbcnx) {
    	exit ('<p>unable to connect to the database server at this time.</p>');
    }
    
    //select the jokes database
    if (!@mysql_select_db(‘ijdb’)) {
    	exit ('<p>unable to connect to the server.</p>');
    }
    
    //If a joke has been submitted add it to the database
    if (isset($_POST[‘joketext’])) {
    $joketext = $_POST[‘joketext’];
    $sql = "INSERT INTO joke SET
    	joketext=’$joketext’ ,
    	jokedate=CURDATE( )";
    if (@mysql_query($sql)) {
    	echo '<p>Your joke has been added.</p>';
    } else {
    	echo 'Your joke is crap and has not been added: ' . mysql_error () . '</p>';
    }
    }
    echo '<p>Here are all the **** jokes in the database</p>';
    //request the text of all the jokes
    $result = @mysql_query ('SELECT joketext FROM joke');
    if (!$result) {
    	exit ('<p>There was an error' . mysql_error . 'In the database</p>');
    }
    //display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    	echo '<p>' . $row['joketext'] . '</p>';
    }
    //when clicked, this link will load this page with the joke submission form displayed
    echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?addjoke=1 ">Add a joke</a></p>' ;
    endif;
    ?>

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    If you look at the code there are different types of quotes - ‘ should be ' and ” should be "
    These different quotes that you have will throw up a parse error which should be displayed to your screen. The fact they dont suggests that the error_reporting is off.

    have a look at www.php.net/error_reporting and alter the setting to show all errors.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, changed all the quotes and placed error_reporting (E_ALL) at the bottom of the page - still a blank one! Any more ideas?!

    Code:
    <?php if (isset ($_GET['addjoke'])): // user wants to add a joke ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Post your stuff here: <br />
    <textarea name="joketext" rows="10" cols="40">
    </textarea>
    </label><br />
    <input type="submit" value="SUBMIT" />
    </form>
    
    <?php else:
    
    //default page display
    //connect to the database server
    
    $dbcnx = @mysql_connect('localhost', 'root', 'arcanum1');
    if (!$dbcnx) {
    	exit ('<p>unable to connect to the database server at this time.</p>');
    }
    
    //select the jokes database
    if (!@mysql_select_db('ijdb')) {
    	exit ('<p>unable to connect to the server.</p>');
    }
    
    //If a joke has been submitted add it to the database
    if (isset($_POST['joketext'])) {
    $joketext = $_POST[joketext];
    $sql = "INSERT INTO joke SET
    	joketext='$joketext' ,
    	jokedate=CURDATE( )";
    if (@mysql_query($sql)) {
    	echo '<p>Your joke has been added.</p>';
    } else {
    	echo 'Your joke is crap and has not been added: ' . mysql_error () . '</p>';
    }
    }
    echo '<p>Here are all the naff jokes in the database</p>';
    //request the text of all the jokes
    $result = @mysql_query ('SELECT joketext FROM joke');
    if (!$result) {
    	exit ('<p>There was an error' . mysql_error . 'In the database</p>');
    }
    //display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    	echo '<p>' . $row['joketext'] . '</p>';
    }
    //when clicked, this link will load this page with the joke submission form displayed
    echo '<p><a href=" ' . $_SERVER['PHP_SELF'] . '?addjoke=1 ">Add a joke</a></p>' ;
    endif;
    ?>
    <?php error_reporting(E_ALL); ?>
    Thanks again! ST

  10. #10
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In case its useful knowledge, when 'viewing source' everything below the body tag has disappeared.

    ST


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •