Go Back   Cyber Tech Help Support Forums > Software > Web Development & Graphic Design

Notices

Reply
 
Topic Tools
  #1  
Old September 3rd, 2006, 05:50 PM
karlosio's Avatar
karlosio karlosio is offline
Member
 
Join Date: Jul 2006
Location: Scottish Highlands
Age: 27
Posts: 89
Unhappy Unable to view form (register.php page) for my site

Hi,

Im trying to create a membership system for my website however the register page does not display the form when viewed in a browser , here is my code below..

Database Entry:

Code:
 CREATE TABLE `user_system` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT,
`username` VARCHAR( 250 ) NOT NULL ,
`password` VARCHAR( 250 ) NOT NULL ,
`email` VARCHAR( 250 ) NOT NULL ,
`is_activated` TINYINT( 1 ) NOT NULL DEFAULT '0',
`activation_code` VARCHAR( 25 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MyISAM
functions.php

PHP Code:
<?php
function generateCode($length 10)
{
$password="";
$chars "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
srand((double)microtime()*1000000);
for (
$i=0$i<$length$i++)
{
$password $password substr ($charsrand() % strlen($chars), 1);
}
return 
$password;
}
?>
register.php

PHP Code:
<?php
require("config.php");
require(
"functions.php");
//echo some styles to spice it up...
echo "
<style>
body
{
background: #131313;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
"
;
switch(
$_GET['action'])
{
case 
"new":
//--------------------------------------
// [New Registration]
//--------------------------------------
if(!isset($_POST['register']))
{
echo 
"<form action='register.php?action=new' method='POST'>
Username: <br />
<input type='text' name='username' class='register_box'>
<br />
Email: <br />
<input type='text' name='email' class='register_box'>
<br />
Password: <br />
<input type='password' name='password' class='register_box'>
<br />
<input type='submit' name='register' value='New Registration!' class='register_box'>
</form>"
;
}
elseif(isset(
$_POST['register']))
{
$username mysql_real_escape_string($_POST['username']);
$password mysql_real_escape_string($_POST['password']);
$email mysql_real_escape_string($_POST['email']);
$activation_code generateCode(25);
$userq "SELECT username FROM user_system WHERE username = '$username' LIMIT 1";
$emailq "SELECT email FROM user_system WHERE email = '$email' LIMIT 1";
//put errors into an array
$errors = array();
if(empty(
$username))
{
$errors[] = "The username field was blank! <br />";
}
if(
mysql_num_rows(mysql_query($userq)) > 0)
{
$errors[] = "The username given is already in use! Please try another one! <br />";
}
if(empty(
$password))
{
$errors[] = "The password field was blank! <br />";
}
if(empty(
$email))
{
$errors[] = "The email field was blank! <br />";
}
if(
mysql_num_rows(mysql_query($emailq)) > 0)
{
$errors[] = "The email given is already in use! Please try another one! <br />";
}
if(
count($errors) > 0)
{
foreach(
$errors as $err)
{
echo 
$err;
}
}
else
{
$sqlq "INSERT INTO user_system (username, password, email, is_activated, activation_code)";
$sqlq .= "VALUES ('$username', '".md5($password)."', '$email', '0', '$activation_code')";
mysql_query($sqlq) or die(mysql_error());
echo 
"Thanks for registering!
You will recieve an email shortly containing your validation code,
and a link to activate your account!"
;
mail($email"New Registration, www.domain.com""
Thanks for registering on SITE NAME.
Here are your login details:
Username: "
.$username."
Password: "
.$password."
In order to login and gain full access, you must validate your account.
Click here to validate:
http://www.site.com/register.php?action=activate&user="
.$username."&code=".$activation_code."
Thanks!
[Webmaster]
"
);
}
}
break;
}
?>
Reply With Quote
  #2  
Old September 3rd, 2006, 06:08 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,023
Blog Entries: 1
How are you loading it?
You have it setup so that you need the querystring to make the form show
?action=new


Also, with that amount of HTML I would suggest that you break in and out of HTML & PHP instead of using HTML within PHP strings.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #3  
Old September 3rd, 2006, 06:34 PM
karlosio's Avatar
karlosio karlosio is offline
Member
 
Join Date: Jul 2006
Location: Scottish Highlands
Age: 27
Posts: 89
Not sure what you mean by how you loading it, sorry im a php noob Im running it through Apache if thats any help

Is there anyway of making it display, do i have to remove the ?action=new ?...
Reply With Quote
  #4  
Old September 3rd, 2006, 06:38 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,023
Blog Entries: 1
If you load your page using
http://domain.com/register.php then it will be blank because you have set the switch to look for a querystring variable.

http://domain.com/register.php?action=new will display your form.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #5  
Old September 3rd, 2006, 06:53 PM
karlosio's Avatar
karlosio karlosio is offline
Member
 
Join Date: Jul 2006
Location: Scottish Highlands
Age: 27
Posts: 89
aha i got you

its working now, ill try and make it move in between html and php to reduce the amount of html contained within the php code, thanks degsy
Reply With Quote
  #6  
Old September 3rd, 2006, 07:04 PM
karlosio's Avatar
karlosio karlosio is offline
Member
 
Join Date: Jul 2006
Location: Scottish Highlands
Age: 27
Posts: 89
ahhhh im now trying to add an activation case underneath the last line removing the last } of the previous code and adding on the below:

PHP Code:

// Added onto bottom of code above

case "activate":
//--------------------------------------
// [Activate Account]
//--------------------------------------
if(isset($_GET['user']) && isset($_GET['code']))
{
$username mysql_real_escape_string($_GET['user']);
if(
mysql_num_rows(mysql_query("SELECT id FROM user_system WHERE username = '$username'")) == 0)
{
echo 
"That username is not in the database!";
}
else
{
$activate_query "SELECT is_activated FROM user_system WHERE username = '$username'";
$is_already_activated mysql_fetch_object(mysql_query($activate_query)) or die(mysql_error());
if(
$is_already_activated->is_activated == 1)
{
echo 
"This user is already activated!";
}
else
{
$code mysql_real_escape_string($_GET['code']);
$code_query "SELECT activation_code FROM user_system WHERE username = '$username' LIMIT 1";
$check_code mysql_fetch_object(mysql_query($code_query)) or die(mysql_error());
if(
$code == $check_code->activation_code)
{
$update "UPDATE user_system SET is_activated = '1' WHERE username = '$username'";
mysql_query($update) or die(mysql_error());
echo 
"User $username has been activated! Thanks! You may now login!";
}
else
{
echo 
"The activation code was wrong! Please try again!";
}
}
}
}
else
{
echo 
"No ID or user given to activate!";

This is causing an error when i view it in the browser

Parse error: parse error, unexpected $ in /home/fhlinux191/d/domain.co.uk/user/htdocs/members/register.php on line 153

Line 153 is the ?> closing code of php and theirs no $ symbol there, any ideas
Reply With Quote
  #7  
Old September 3rd, 2006, 07:18 PM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,023
Blog Entries: 1
please post the full script
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #8  
Old September 3rd, 2006, 07:19 PM
Buzz's Avatar
Buzz Buzz is offline
Cyber Tech Help Moderator
 
Join Date: Sep 2000
O/S: MacOS
Location: Oregon, USA
Posts: 3,324
Check the line above (line 152) often it's a missing ; or ) that causes the error. Also need a break attribute in the php if you are using a switch case.

Also you may want to add standard html structure to the page such as a DOCTYPE tag, head tag, title tag etc.
__________________
Scott
Moderator : Macintosh : Website & Graphics
Adobe Certified Expert: Illustrator
Royalty-Free Vector Stock Art
Reply With Quote
  #9  
Old September 4th, 2006, 12:07 AM
karlosio's Avatar
karlosio karlosio is offline
Member
 
Join Date: Jul 2006
Location: Scottish Highlands
Age: 27
Posts: 89
Quote:
Originally Posted by Buzz View Post
Check the line above (line 152) often it's a missing ; or ) that causes the error. Also need a break attribute in the php if you are using a switch case.

Also you may want to add standard html structure to the page such as a DOCTYPE tag, head tag, title tag etc.
That worked, thanks buzz

What Im trying to accomplish is to test run a membership system where users can register and create/edit their profile on my site. Then after success modify it so it integrates with my site.

Ive come across yet another problem which is baffling me (probably due to my own lack of php/mysql ) I have created a log on script and a view profile script, when a user logs in they get the message You have been successfully logged in! however I would also like to link a view their profile link to the registered database id, but I cant get it to work all i get returned is There was no member ID to view a profile for and the link returns

http://www.mysite.com/members/view_p...php?member_id=

...missing the database id of the logged in user at the end of the url

here is my code for the two pages:

login.php

PHP Code:
<?php
session_start
();
      require(
"config.php");
      require(
"functions.php");
      
//echo some styles to spice it up...
      
echo "
      <style>
      body
      {
      background: #131313;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      .register_box
      {
      border: 1px solid #323232;
      background: #202020;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      </style>
      "
;
      if(!isset(
$_SESSION['logged_in']))
      {
      if(!isset(
$_POST['check_login']))
      {
      echo 
"
      <form action='login.php' method='post'>
      Username: <input type='text' name='username' />
      <br />
      Password: <input type='password' name='password' />
      <br />
      <input type='submit' name='check_login' value='Login' />
      </form>
      "
;
      }
      elseif(isset(
$_POST['check_login']))
      {
      
$username mysql_real_escape_string($_POST['username']);
      
$password md5($_POST['password']);
      if(empty(
$_POST['password']) || empty($username))
      {
      echo 
"You left a field blank!";
      }
      else
      {
      
$check_login mysql_query("SELECT username, password, id FROM user_system WHERE username = '$username' AND password = '$password' LIMIT 1");
      if(
mysql_num_rows($check_login) > 0)
      {
      
$_SESSION['logged_in'] = 1;
      
$_SESSION['username'] = $username;
      echo 
"You have been successfully logged in!<br />
      <a href='viewprofile.php?member_id=$check_login[id]'>View Profile</a>
      "
;
      }
      else
      {
      echo 
"Sorry. Wrong password, or user does not exist.";
      }
      }
      }
      }
      else
      {
      echo 
"You are already logged in.";
      }
?>
view_profile.php

PHP Code:
<?php
      
require("config.php");
      require(
"functions.php");
      
//echo some styles to spice it up...
      
echo "
      <style>
      body
      {
      background: #131313;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      .register_box
      {
      border: 1px solid #323232;
      background: #202020;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      </style>
      "
;
      
// if the variable member_id has been set, or there is a value assigned to it...
      
if(isset($_GET['member_id']))
      {
      
$member_id = (INT)$_GET['member_id'];
      
$member_info mysql_query("SELECT username, email FROM user_system WHERE is_activated = '1' AND id = '$member_id' LIMIT 1");
      if(
mysql_num_rows($member_info) > 0)
      {
      
// we can go ahead and assign it to an array because this user exists
      
$profile_info mysql_fetch_assoc($member_info);
      echo 
"
      <h1>$profile_info[username]</h1>
      <br />
      <br />
      <b>Email:</b> <a href='mailto:$profile_info[email]'>$profile_info[email]</a>
      <br />
      <br />
      "
;
      }
      else
      {
      echo 
"That member does not exist, or is not activated yet!";
      }
      }
      else
      {
      echo 
"There was no member ID to view a profile for!";
      }
?>

Last edited by karlosio; September 4th, 2006 at 12:20 AM.
Reply With Quote
  #10  
Old September 4th, 2006, 12:15 AM
Buzz's Avatar
Buzz Buzz is offline
Cyber Tech Help Moderator
 
Join Date: Sep 2000
O/S: MacOS
Location: Oregon, USA
Posts: 3,324
PHP Code:
$check_login mysql_query("SELECT username, password, id FROM user_system WHERE username = '$username' AND password = '$password' LIMIT 1");
      if(
mysql_num_rows($check_login) > 0)
      {
          
$_SESSION['logged_in'] = 1;
          
$_SESSION['username'] = $username;
          
$id $check_login['id'];
          echo 
"You have been successfully logged in!<br />";
          echo 
'<a href="http://www.mysite.com/members/view_p...php?member_id='.$id.'">View Profile</a>';
      } 
maybe

In short, you need to pull the number from the id field in the log in query in order to pass it to a link.
__________________
Scott
Moderator : Macintosh : Website & Graphics
Adobe Certified Expert: Illustrator
Royalty-Free Vector Stock Art
Reply With Quote
Reply

Bookmarks

Topic Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:05 PM.

[ RSS ]