SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Chapter 4 Kevin Yanks Jokes.php

    Hi everyone!

    Firstly, I must stress that I'm very very new to PHP and MySQL, so please bare with me :-)

    I have typed out this code and checked over and over but I can't seem to find any more errors, I have also downloaded Kevin Yanks version of the file and I'm getting exactly the same results. I have put the file in my inetpub/wwwroot folder and I'm using the command:

    http://localhost/jokes.php

    Just like all my other scripts. However this file won't load, it just displays a blank page (both files, not just mine)

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>The Internet Joke Database</title>
      </head>
      <body>
        <?php if (isset($_GET['addjoke'])): // User wants to add a joke 
    	?>
    	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    	  <label>Type your joke 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', '********');
    	  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 locate the joke ' . 'database at this time.</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 '<p>Error adding submitted joke: ' . mysql_error() . '</p>';
    		}
    	  }
    	  echo '<p>Here are all the jokes in our database:</p>';
    	  //Request the text of all the jokes
    	  $result = @mysql_query('SELECT joketext FROM joke');
    	  if (!$result) {
    	    exit('<p>Error performing query: ' . mysql_error() . '</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; 
    	?>
    	
      </body>
    </html>
    I'm getting nothing displayed at all, it's just a blank page, when I view the source code, there is no php tags and it ends at the opening body tag. Kevin Yanks source code does exactly the same thing.

    Can anyone help me?

    Russ

  2. #2
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you create a .php file with the only contents being:
    <?php
    phpinfo();
    ?>

    See if this displays anything at all and post back.
    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  3. #3
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks, sorry I'm a little unsure of where to type this...

    I made a new document and included that before the doctype tag and it displayed my php 5.2 version information. The page loaded fine with the command.

    Russ

  4. #4
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok - yeah thats pretty much what i neded you to do - I just wanted to make sure that php/mysql was installed correctly on your machine

    This line:
    PHP Code:
    if (isset($_GET['addjoke'])): 
    And this line:
    PHP Code:
    else: 
    look a little strange to me....There should be some brackets at the start and end of the if and else
    eg
    PHP Code:
    if (isset($_GET['addjoke']))
    {

    }
    else
    {


    But i dont think that is your problem, as you didnt mention whether you were getting any errors or not.

    Any other takers on this one?
    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  5. #5
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I understand there are two ways to write if else clauses, either like
    If (condition) :
    else (condition) :

    or

    If (condition) {
    }
    else (condition) {
    }

    But like you say, I'm pretty sure this isn't my problem as nothing is happening at all here, and the original code seems to generate the same error.

    Could it be something else in my code perhaps?

    Russ

  6. #6
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes sorry apologies - thats just not a syntax that I have seen recently so it through me a little, especially as you were mixing the 2 types of syntax.......

    I cant see anything in your code right now (havent the time to examine it indepth) - but I wouls suggest removing some of the functionaility to see if yu can get something very basic working - perhaps just displaying all of the jokes:

    PHP Code:
    <?php
    echo '<p>Here are all the jokes in our database:</p>';
    //Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result
    {
        exit(
    '<p>Error performing query: ' mysql_error() . '</p>');
    }
    //Display the text of each joke in a paragraph
    while ($row mysql_fetch_array($result)) 
    {
        echo 
    '<p>' $row['joketext'] . '</p>';
    }
    ?>
    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  7. #7
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's odd, for some reason the form isn't being written to the screen, if I save the file as html it displays the form with the php code as expected. So what php tag or piece of syntax be interfering with the rendering of the form. Could it be something to do with the version of PHP I'm using (5.2)?

    If anyone knows what is wrong I'd really appreciate some help as I can't move along anymore if I know the rest of my code isn't going to work anyway.

    Thanks

    Russ

  8. #8
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I took out:

    <?php if (isset($_GET['addjoke'])): // User wants to add a joke
    ?>

    else: (in the next php tag)

    endif: (at the bottom of the script)

    and it displayed the html form that it's been lacking......

    Can anybody help me from this, is there something wrong in these lines?

    Russ

  9. #9
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Yes atlast :-)

    Hi everyone!

    I have been stuck all day trying to figure this one out and after reading through almost all of the threads I could find I was almost ready to give up for today. I realised something must have been up with php but wasn't sure what it was. After reading through this link:-

    http://www.sitepoint.com/forums/show...cting+database

    I realised that my extension_dir was pointing the wrong place. I followed the book as best as I could, but it would appear that the new download of php 5.2 downloads to the c:\php\php-5.2.0-Win32 and not C:\php. I should have noticed this problem but me being a newbie I guess I can be forgiven. So if anyone else is having a problem with blank pages, whilst trying to do something like I've been doing......just check to make sure your extension_dir is pointing to the right place.

    Without these forums we 'could' all be lost.......maybe theres hope for us newbies after all :-)

    Thanks everyone

    Russ


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
  •