Another Parse Error

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

robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Another Parse Error

Post by robjime »

I'm probably missing something simple...Theres a parse error on one of these 3 lines.

Code: Select all

<? php $Subject = "Your Sonicage Blog Account";
		$Message = "Welcome to Sonicage Blog! Heres your information.<br> Name: $name <br> Username: $username <br> Password: $password <br><br> Your blog is viewable at http://www.sonicage.com/$username. To visit your control panel login at sonicage.com/blog/login.php. <br> Thank You";
		$headers = "From: Blog Admin <webmaster@sonicage.com>\r\n";

?>
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

are there any escape characters not being handled in the variables?
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post by robjime »

im not sure what that means
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

well, for instance, do the variables (such as $name) contain any characters that might cause the script to stop such as quotation marks or back slashes?
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post by robjime »

nope
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

post the exact error plz
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

#as Phenom said state the error please, i cant see nothing at this moment that might cause an error..
#however this might look a bit better.
$Subject = "Your Sonicage Blog Account";
$Message = "Welcome to Sonicage Blog! Heres your information.<br> Name: '".$name."' <br> Username: '".$username."' <br> Password: '".$password."' <br><br> Your blog is viewable at http://www.sonicage.com/'".$username."'. To visit your control panel login at sonicage.com/blog/login.php. <br> Thank You";
$headers = "From: Blog Admin <webmaster@sonicage.com>\r\n";
lolpix
Forum Commoner
Posts: 41
Joined: Sat Jul 17, 2004 2:20 am

Post by lolpix »

This bit of code looks okay...

Code: Select all

<?php 

$Subject = "Your Sonicage Blog Account";
 
$Message = "Welcome to Sonicage Blog! Here is your information:
           <br />
           Name: $name
           <br /> 
           Username: $username
           <br />
           Password: $password
           <br />
           <br />
           Your blog is viewable at http://www.sonicage.com/$username. To visit your control panel login at sonicage.com/blog/login.php.
           <br />
           Thank You"; 
      
$headers = "From: Blog Admin <webmaster@sonicage.com>\r\n"; 

?>
(I have re-written it an atypical PHP format, which would be one that other people can reasonably be expected to read ;) )
lolpix
Forum Commoner
Posts: 41
Joined: Sat Jul 17, 2004 2:20 am

Post by lolpix »

Maybe this is causing problems?

Code: Select all

www.sonicage.com/$username.
Perhaps it is trying to concatenate $username with a variable (because of the period) that never comes?
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post by robjime »

Parse error: parse error in /home/robjime/public_html/blog/functions.php on line 39

Code: Select all

<?php
require_once ('functions.php');

$valid = TRUE;
$name=$_POST['name'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
if (isset ($_POST['submit'])) {
    foreach($_POST as $key=>$value) {
      $$key = $value;
    }
    
    
    $em = checkEmail($email);
    $valid = $valid && $em;
    $ps = checkPassword($password);
    $valid = $valid && $ps;
    $ps2 = $password == $password2;
    $valid = $valid && $ps2;
    $nusr = newuser($username);
    $valid = $valid && nusr;	
   
    if ($valid) {
		$user="*********";
		$passwrd="********";
		$database="********";
	

		mysql_connect(localhost,$user,$passwrd);
		@mysql_select_db($database) or die( "Unable to select database");

		$query = "INSERT INTO users VALUES ('','$username','$pass','$name','$email')";
		mysql_query($query);
		mysql_close();
		$To = $email;
		$Subject = "Your Sonicage Blog Account";
		$Message = "Welcome to Sonicage Blog! Heres your information.<br> Name: $name <br> Username: $username <br> Password: $password <br><br> Your blog is viewable at http://www.sonicage.com/$username! To visit your control panel login at sonicage.com/blog/login.php. <br> Thank You";
		$headers = "From: Blog Admin <webmaster@sonicage.com>\r\n";
		mail($To, $Subject, $Message, $headers);
        echo "Your information has been emailed to you! Proceed to login <a href='login.php'>Click Here</a>";
        exit;
    }
} else {
    $em = $ps = $ps2 = $nusr = TRUE;

echo '<form name="register" method="post" action="register.php">
  <table width="100%" border="0">
    <tr> 
      <td>Name:</td>
      <td><input name="name" type="text" id="name"></td>
    </tr>
    <tr> 
      <td'; if(!$em){echo 'class="error"';} echo '>Email:</td>
      <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr> 
      <td'; if(!nusr) {echo 'class="error"';} echo '>Username:</td>
      <td><input name="username" type="text" id="username"><br>'; if(!nusr) {echo '<font color="#FF0000" size="2">Username already taken!</font>';} echo '</td>
    </tr>
  
    <tr> 
      <td'; if(!($ps && $ps2)) {echo 'class="error"';} echo'>Password:</td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr>
      <td>Password must be at least 6 chars. in lenth.</td>
    </tr>
    <tr> 
      <td'; if(!($ps && $ps2)) {echo 'class="error"';} echo '>Re-type Password:</td>
      <td><input type="password" name="password2"></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" value="Register">
        <input type="reset" name="Submit2" value="Reset"></td>
    </tr>
   
  </table>
  </form>';
}
?>
functions.php

Code: Select all

<?php

function checkPassword($password) {
  $length = strlen ($password);
  if ($length < 6) {
    return FALSE;
  }
}

function checkEmail($email) {
  $pattern = "/^[A-z0-9\._-]+"
         . "@"
         . "[A-z0-9][A-z0-9-]*"
         . "(\.[A-z0-9_-]+)*"
         . "\.([A-z]{2,6})$/";
  return preg_match ($pattern, $email);
}

function newuser($username) {
		$user="robjime";
		$passwrd="888888888";
		$database="888888888_";
	

		mysql_connect(localhost,$user,$passwrd);
		@mysql_select_db($database) or die( "Unable to select database");	
		
		$query="SELECT * FROM users";
		$result=mysql_query($query);
		$num=mysql_numrows($result);
		mysql_close();
		$i=0;
		while ($i < $num) {
		
		$dbuser=mysql_result($result,$i,"user");
		$i++;
	}

	if(preg_match($username, $dbuser) {
		return FALSE;
	}
}

?>

feyd | removed user/password
Last edited by robjime on Sat Jul 31, 2004 11:01 am, edited 1 time in total.
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Post by zenabi »

You are missing a closing bracket at the end of your code. It should be this:

Code: Select all

if(preg_match($username, $dbuser)) {  /* note the extra ) */
      return FALSE; 
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

also, I noticed that $nusr is used without the dollar sign twice in the echo junk..
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

i have all your passwords!!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Don't be like that brandan.

Robjime, please change all your passwords (ftp, db, etc).

some members may use them for malicious things.

And remember, never post direct code without double checking that passwords are edited out (****, etc..).
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

be like what? i said what you said in only 5 words. that's optimization at its best!
Post Reply