Jump to content

Errors in code?


Drewdle

Recommended Posts

Hey,

 

I'm having trouble with errors on a script I found on the net.

 

Heres the script:

<?php 
// Start session and check if user is already registered and logged in 
session_start(); 
if ($_SESSION['s_logged_n'] = 'true'){ 
echo "You are already registered user"; 
// Else if register button has been pressed continue with script 
} else { 
if (isset($_POST['register'])){ 
// Include config file 
include "config.php"; 
// Define variables 
$username = $_POST['username']; 
$email = $_POST['email']; 
$password = $_POST['password']; 
$password_confirm = $_POST['password_confirm'];

$ip = $_POST['ip']; 
$date = $_POST['date'];

$pass = $_POST['password']; 
// Add slashes and trim 
$username = addslashes(trim($username)); 
$email = addslashes(trim($email)); 
$password = addslashes(trim($password)); 
$password_confirm = addslashes(trim($password_confirm)); 
// Check if any field is left blank, if it is it will say so to user and stop them registering
if ((((empty($username)) || (empty($email)) || (empty($password)) || (empty($password_confirm))))){ 
echo 'You must fill in all fields'; 
// Else if all fields are filled in continue 
} else { 
// Check if email is vaid and has a monkey and dot 
if ((!strstr($email , '@')) || (!strstr($email , '.'))){ 
echo 'You must enter valid email address'; 
// If everything is ok continue and query table 
} else { 
$check = "SELECT * FROM users WHERE username = '$username' LIMIT 1″; 
$check_query = mysql_query($check); 
$count = mysql_num_rows($check_query); 
// Check if username is already taken 
if ($count = 1){ 
echo 'That username is already taken'; 
// If it’s not continue and check if passwords match each other 
} else { 
if ($password = $password_confirm){ 
// Make password have md5 hash 
$password = md5($password); 
// Genereta activation key 
$act = mt_rand(1, 500).‘f78dj899dd’; 
$actkey = sha1($act); 
// Insert new user data to table 
$query = "INSERT INTO users (username, email, password, ip, date, actkey) VALUES ('$username', '$email', '$password', '$ip', '$date', '$actkey')";
$result = mysql_query($query); 
// Send activation email to user 
$send = mail($email, "Registration Confirmation", "Thank you for registering at my website.\n\nYour username and password is below, along with details on how to activate your account.\n\nUsername: ".$username."\nPassword: ".$pass."\n\nClick the link below to activate your account:\n".$your_site."/activate.php?id=".$actkey."\n\nPlease do not reply to this e-mail, this is an automated mailer.\n\nThanks", "FROM: ".$your_email."); 
// If both registration and sending mail was ok output it 
if (($result)&&($send)){ 
echo "Thank you for registering, your account has been created, however you must activate it before you can use it, visit your email inbox for activation details.";
} else { 
// Else if there is error with creating account say so 
echo "There was an error creating your account"; 
}  
} else { 
// If passwords don’t match each other say s 
echo "Your password do not match each other"; 
} 
} 
} 
} 
} else { 
// If someone just try to open file stop them 
echo "You must register over form"; 
} 
} 
?>

 

and the error is: Parse error: syntax error, unexpected T_STRING in /home/chillp/public_html/site/login/register.php on line 51

 

I'm not 100% but I think line 51 is: $query = "INSERT INTO users (username, email, password, ip, date, actkey) VALUES ('$username', '$email', '$password', '$ip', '$date', '$actkey')";

 

I can't find the error and I'm getting a bit stressed now as when I first ran the script their were several errors! This one however I cant seem to put my finger on...

 

Cheers

Link to comment
Share on other sites

Your error starts right here:

$check = "SELECT * FROM users WHERE username = '$username' LIMIT 1&#8243;; 

 

You have '&#8243;' which is the ascii value for a double quote.  I don't know how that would have gotten there but replace it with a double quote.

 

(You thought line 51 was something else because your formatting is messed up.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.