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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Benjipie
Forum Newbie
Posts: 11
Joined: Sun Dec 07, 2008 7:04 am

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

Post 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>
 
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

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

Post 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.
Benjipie
Forum Newbie
Posts: 11
Joined: Sun Dec 07, 2008 7:04 am

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

Post 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)
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

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

Post 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);
Benjipie
Forum Newbie
Posts: 11
Joined: Sun Dec 07, 2008 7:04 am

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

Post by Benjipie »

thanks for the help...

but it still wont work.

Any other ideas?

Thanks again.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

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

Post by watson516 »

How is it not working? Nothing shows up? Errors? The php gets printed as html?
Benjipie
Forum Newbie
Posts: 11
Joined: Sun Dec 07, 2008 7:04 am

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

Post 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?)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

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

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

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

Post 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.
Post Reply