Page 1 of 1

PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 10:49 am
by Benjipie
Hi,
I'm trying to learn php and MySQL using the book 'Head First PHP & MySQL' (great book!!) but im having trouble with a registration form (where a user registers at the site). The book comes with source code which I've uploaded to my server to test and works fine, but when i use the code for my site none of it works, nothing (the html code before the php works but thats it...none of the php works). Any ideas...this is killing me. I have a feeling its something small thats stopping it but i've been trying to work this out since last saturday!!! Any ideas? :banghead:

Code: Select all

 
<?php
//XMLXSL Transformation class
require_once('../includes/MM_XSLTransform/MM_XSLTransform.class.php'); 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ESL Groups - Register With Us</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Studio7designs - Professional Photography and Graphic Designs, Victoria BC Canada" />
    <meta name="keywords" content="Studio7designs" />
    <meta name="author" content="Aran / Original design: Aran Down - http://www.studio7designs.com" />
    <link rel="stylesheet" type="text/css" href="contentCSS/style.css" />
    <link rel="shortcut icon" href="../favicon/favicon.png" />
    <link rel="stylesheet" type="text/css" media="all" href="contentCSS/bannerHills.css" />
    <link rel="stylesheet" type="text/css" media="all" href="contentCSS/registerCSS.css" />
    <style type="text/css">
<!--
.style1 {
    color: #669966;
    letter-spacing: 1px;
    border-bottom: 1px solid #ffb400;
    
    }
</style>
 
</head>
 
<body>
 
<?php include('contentIncludes/header.php') ?>
 
<div id="wrapper-content">
<div id="wrapper-menu-page">
 
    <div id="menu-page">
    <h3>&nbsp;</h3>
    <h3>learn more...</h3>
    <ul>
        <li><a href="why_elearning.php">Why online learning?</a></li>
        <li><a href="why_ESL.php">Why ESL Groups?</a></li>
        <li><a href="Whats_great_video.php">Whats so special about <br />the video lessons?</a></li>
    </ul>
    
    <h3>Free Lessons</h3>
    <ul>
        <li><a href="freeBasic.php">The Basics</a></li>
        <li><a href="freeIntermediate.php">Intermediate</a></li>
        <li><a href="freeAdvanced.php">Advanced</a></li>
      </ul>
    <h3>Start Learning</h3>
    <ul>
        <li><a href="fullLibrary.php">See all our lessons</a></li>
        <li><a href="lessonLibrary.php">Lessons arranged by <br />difficulty</a></li>
    </ul>
    
    <p>&nbsp;</p>
</div><!--menu-page-->
</div>
<div id="content">
  <h2 class="style1">Register with ESL Groups</h2>
  <p>Join ESL Groups and learn practical English </p>
  <h2 class="upperCaseHeader">please enter your details</h2><p>
  </p>
  <!---------------------------------------------------------------------THIS IS THE REGISTRATION CODE BELOW------>
<?php
  require_once('scripts/appvars.php');
  require_once('scripts/connectvars.php');
 
  // Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
 
  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST
    $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
    $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
    $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
 
    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
      // Make sure someone isn't already registered using this username
      $query = "SELECT * FROM myTable WHERE username = '$username'";
      $data = mysqli_query($dbc, $query);
      if (mysqli_num_rows($data) == 0) {
        // The username is unique, so insert the data into the database
        $query = "INSERT INTO myTable (username, password, join_date) VALUES ('$username', SHA('$password1'), NOW())";
        mysqli_query($dbc, $query);
 
        // Confirm success with the user
        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';
 
        mysqli_close($dbc);
        exit();
      }
      else {
        // An account already exists for this username, so display an error message
        echo '<p class="error">An account already exists for this username. Please use a different address.</p>';
        $username = "";
      }
    }
    else {
      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
    }
  }
 
  mysqli_close($dbc);
?>
 
  <p>Please enter your username and desired password to sign up to Mismatch.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>Registration Info</legend>
      <label for="username">Username:</label>
      <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />
      <label for="password1">Password:</label>
      <input type="password" id="password1" name="password1" /><br />
      <label for="password2">Password (retype):</label>
      <input type="password" id="password2" name="password2" /><br />
    </fieldset>
    <input type="submit" value="Sign Up" name="submit" />
  </form>
 
 
 
  <br />
or you can email us at <a href="mailto:info@eslGroups.com">info@ESLGroups.com</a>.
  
</div>
</div>
</div>
 
<?php include('contentIncludes/footer.php'); ?>
</body>
</html>
 

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:09 pm
by php_east
turn on errors and see what it says...

Code: Select all

 
<?php
error_reporting(E_ALL);
//XMLXSL Transformation class
:
:
:
 
error_reporting(0); to turn it off.

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:22 pm
by Benjipie
do i turn it off in my PHP ini or type:
error_reporting = (0) in my php page?

(sorry..completely new to PHP)

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:32 pm
by php_east
u put it inside your script, it overides whatever you have in your php so no need to worry about your php settings. it is a runtime instruction. example is posted above.

the format is error_reporting(value);

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:38 pm
by Benjipie
thanks for the help...

but it still wont work.

Any other ideas?

Thanks again.

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:39 pm
by watson516
How is it not working? Nothing shows up? Errors? The php gets printed as html?

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 3:45 pm
by Benjipie
Yeah, nothing shows up, I have a bit of HTML at the top and some links to stylesheets but they wont show up either when i include the error_reporting = (0);

Thanks again though.(any other ideas?)

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 4:44 pm
by califdon
The thing is, about PHP, that if there's a syntax error anywhere in your script, it will usually be detected and the PHP just doesn't output anything, so nothing within the PHP tags will do anything at all. This is very common in debugging PHP scripts, nothing is output, just a blank page.

First, carefully proofread your script, looking for minor things like a missing semicolon or unmatched brackets or parentheses. Then start segmenting your code, commenting out large segments that don't depend on each other, to see if you can isolate the block where it's failing to parse properly. This is sometimes tedious, but it will eventually reveal what part of the script is valid and what part isn't.

Re: PHP code not working....none of it!!

Posted: Sun Mar 01, 2009 8:58 pm
by semlar
Benjipie wrote:Yeah, nothing shows up, I have a bit of HTML at the top and some links to stylesheets but they wont show up either when i include the error_reporting = (0);
I'm not entirely sure you understood his post, that turns error reporting off, I'm pretty sure you want that on.

On line 90 you have this..

Code: Select all

echo '<p>Your new account has been successfully created. You're now ready to <a href="login.php">log in</a>.</p>';
You have a single quote, inside of your single-quoted string. That ends the string. You can't do that.

Re: PHP code not working....none of it!!

Posted: Mon Mar 02, 2009 12:51 pm
by php_east
Benjipie wrote:Yeah, nothing shows up, I have a bit of HTML at the top and some links to stylesheets but they wont show up either when i include the error_reporting = (0);
Thanks again though.(any other ideas?)
:banghead:

turn ON errors and see what it says...

Code: Select all

 
<?php
error_reporting(E_ALL);
//XMLXSL Transformation class
:
:
:
 
error_reporting(0); // to turn it OFF.


error_reporting=(0); is another language called JavaScript.