Unexpected T_string In User.php [resolved]

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Unexpected T_string In User.php [resolved]

demonlord
Ok so i'm working on a site for my chruch, and i seem to be having a little bit of trouble with the user.php file i keep getting the following error:

CODE
Parse error: syntax error, unexpected T_STRING in /home/darkzone/public_html/test/user.php on line 195

and i was wondering if some one could help me with the script.

CODE
<?PHP

session_start();
ob_start();

//Include the configurations
include('config.php');

//Define a few variables
$x = $_GET['x'];
$u = $_GET['u'];

class register {

function displayform($title) {

echo('<fieldset><legend>'.$title.'</legend>
<form method="POST" name="register">
Username:<br />
<input type="text" name="username">*<br /><br />

Password:<br />
<input type="password" name="password1">*<br /><br />

Confirm Password:<br />
<input type="password" name="password2">*<br /><br />

Email:<br />
<input type="text" name="email">*<br /><br />

Real Name:<br />
<input type="text" name="realname">*<br /><br />

Website:<br />
<input type="text" name="website"><br /><br />

Location:<br />
<input type="text" name="location"><br /><br />

<input type="submit" name="register" value="Register!">
</form>
</fieldset>');

}

function process($username, $password1, $password2, $email, $realname, $website, $location) {

//Lets define the Queries for searching
$SearchUN = mysql_query("
SELECT *
FROM `users`
WHERE `username` = '$username'");

if(!$SearchUN) die(mysql_error());

$SearchEM = mysql_query("
SELECT *
FROM `users`
WHERE `email` = '$email'");

if(!$SearchEM) die(mysql_error());

$s1 = mysql_fetch_array($SearchUN);
$s2 = mysql_fetch_array($SearchEM);

//Did they leave any vital fields empty?
if(!$username || !$password1 || !$password2 || !$email || !$realname) {
echo('Please fill in all required fields!');
} elseif($password1 !== $password2) {
echo('The supplied passwords do not match.');
} elseif($s1[id]) {
echo('That user already exists.');
} elseif($s2[id]) {
echo('That email is already in use.');
} else {
$InsertQRY = mysql_query("
INSERT INTO
`users`
(
`username`,
`password`,
`email`,
`realname`,
`website`,
`location`
)
VALUES
(
'$username',
'md5($password2)',
'$email',
'$realname',
'$website',
'$location'
)");

if(!$InsertQRY) die(mysql_error());

echo('You have successfully registered!');
}

}

}
class profile {

function edit_display($title) {

//Define the Search query, to fetch information
$SearchQRY = mysql_query("
SELECT *
FROM `users`
WHERE
`username` = '$_SESSION[username]'
");

if(!$SearchQRY) die(mysql_error());

$user = mysql_fetch_array($SearchQRY);

echo('<fieldset><legend>'.$title.'</legend>
<form method="POST" name="edit">

Email:<br />
<input type="text" name="email" value="'.$user[email].'"><br /><br />

Real Name:<br />
<input type="text" name="realname" value="'.$user[realname].'"><br /><br />

Website:<br />
<input type="text" name="website" value="'.$user[website].'"><br /><br />

Location:<br />
<input type="text" name="location" value="'.$user[location].'"><br /><br />

<input type="submit" name="edit" value="Edit Profile!">
</form>
</fieldset>');
}

function edit_process($email, $realname, $website, $location) {

//Define search query, again, used to replace info if its empty
$SearchQRY = mysql_query("
SELECT *
FROM `users`
WHERE
`username` = '$_SESSION[username]'
");

if(!$SearchQRY) die(mysql_error());

$user = mysql_fetch_array($SearchQRY);

if(!$email) {
$email = $user[email];
}
if(!$realname) {
$realname = $user[realname];
}

//Update the information
$UpdateQRY = mysql_query("
UPDATE `users`
SET
`email` = '$email',
`realname` = '$realname',
`website` = '$website',
`location` = '$location'
");

if(!$UpdateQRY) die(mysql_error());

echo('You have successfully updated your profile!');

}

function view($id) {
//Define Query for searching for user info

$SearchQRY = mysql_query("
SELECT *
FROM `users`
WHERE
`id` = '$id'
");

if(!$SearchQRY) die(mysql_error());

$user = mysql_fetch_array($SearchQRY);

if(mysql_num_rows($SearchQRY) == 0) {
echo('Invalid Member ID.');
} else {
echo('<fieldset><legend>'.$user[username].''s Profile</legend>
Username: '.$user[username].'<br />
Email: '.$user[email].'<br />
Real Name: '.$user[realname].'<br />
Website: '.$user[website].'<br />
Location: '.$user[location].'
</fieldset>');
}
}

}
class log {

function login_process($username, $password) {

//Find the information
$FindInfo = mysql_query("
SELECT *
FROM `users`
WHERE
`username` = '$username'
AND
`password` = 'md5($password)'
");

if(!$FindInfo) die(mysql_error());

$F = mysql_fetch_array($FindInfo);

if(!$F[id]) {
echo('Sorry, those credentials are incorrect.');
} else {
$_SESSION['username'] = $username;
$_SESSION['password'] = md5($password);
$_SESSION['id'] = $F[id];

echo('You have been successfully logged in!');
}

}

function login_display($title) {

echo('<fieldset><legend>'.$title.'</legend>
<form method="POST" name="login">
Username:<br />
<input type="text" name="username"><br /><br />

Password:<br />
<input type="password" name="password"><br /><br />

<input type="submit" name="login" value="Login!">
</form>
</fieldset>');

}

function logout() {

header('Location: index.php');

$_SESSION['username'] = "";
$_SESSION['password'] = "";

}

}
$register = new register;

$log = new log;

$profile = new profile;

if(!$_SESSION['username']) {
echo('<a href="?x=register">Register</a> | <a href="?x=login">Login</a><br /><br />');
} else {
echo('<a href="?x=editprofile">Edit Profile</a> | <a href="?x=viewprofile&u='.$_SESSION['id'].'">View Profile</a><br /><br />');
}

if(!$x) {
echo('Welcome to the users system!');
} elseif($x == "register") {

if($_SESSION['username']) {
echo('You cannot register while logged in!');
} else {

if($_POST['register']) {
$register->process($_POST['username'], $_POST['password1'], $_POST['password2'], $_POST['email'], $_POST['realname'], $_POST['website'], $_POST['location']);
} else {
$register->displayform("Register An Account");
}
}

} elseif($x == "login") {

if($_SESSION['username']) {
echo('You are alreadfy logged in!');
} else {
if($_POST['login']) {
$log->login_process($_POST['username'], $_POST['password']);
} else {
$log->login_display("Login To Your Account");
}
}

} elseif($x == "logout") {

if(!$_SESSION['username']) {
echo('You are alreadfy logged out!');
} else {
$log->logout();
}
} elseif($x == "editprofile") {

if(!$_SESSION['username']) {
echo('You must be logged in to edit your profile!');
} else {
if($_POST['edit']) {
$profile->edit_process($_POST['email'], $_POST['realname'], $_POST['website'], $_POST['location']);
} else {
$profile->edit_display("Edit Your Profile");
}
}

} elseif($x == "viewprofile") {
$profile->view($u);
}

?>

 

 

 


Reply

chappill
Well I'm not too good at php but I've seen this problem loads. T_string refers to the $ whatever thing (see I don't know what even thats called).
CODE
$user = mysql_fetch_array($SearchQRY);

I believe that is your problem but unless you tell us where line 195 is we can't do much, without tediously checking the whole script :/. Hope thats helped a little if not then ahh well lol.

Reply

truefusion
Line 195 would be:
CODE
echo('<fieldset><legend>'.$user[username].''s Profile</legend>

You forgot to escape the single quote before the letter S. It should be:
CODE
echo('<fieldset><legend>'.$user[username].'\'s Profile</legend>

Reply

Live-Dimension
Here's the problem - sorry for lack of "technical" words but they've escaped me for the moment. First - you don't need brackets around echo functions.

This does the same thing, and the first method is most preferred too as it's easier to read.
echo "text";
echo ("text");

So, to what's producing the error.
CODE
echo('<fieldset><legend>'.$user[username].''s Profile</legend>


What you've tried to do is put in a ' but in your current setting that ends the string. There's two ways to do this.

One - put in a slash \ right before the second '. The \ makes the second ' as escaped. What this means is that php sees it as text, and not part of the syntax. The other is to use 'rabbit ears' aka ". Compare these.
CODE
echo('<fieldset><legend>'.$user[username].'\'s Profile</legend>
Username: '.$user[username].'<br />
Email: '.$user[email].'<br />
Real Name: '.$user[realname].'<br />
Website: '.$user[website].'<br />
Location: '.$user[location].'
</fieldset>');


echo "<fieldset><legend>{$user[username]}'s Profile</legend>
Username: {$user[username]}<br />
Email: {$user[email]}<br />
Real Name: {$user[realname]}<br />
Website: {$user[website]}<br />
Location: {$user[location]}
</fieldset>";

Yes, there's significant difference between ' and ". Either can be used to start a string and end a string. The ending one has to be the same as the starting one. " is more special then your standard text - and here's why.

Minus the last two, all of these are valid and will echo This is test text.
CODE
$string = "test";

echo "This is $string test"; //Check Note
echo 'This is '.$string.' test';
echo "This is {$string} test";


echo 'This is $string test"; // outputs   This is $string test
echo 'This is {$string} test"; // outputs   This is {$string} test

Note This method can only be used with simple variables. They cannot be used with arrays where you can select the position. This is what the {} are for. For Example.
CODE
echo "This is {'te'.'st'} text";

Note the addition taking place? You can do almost anything inside that bracket.

To sum up - You can use "" and ''. You can use them inside each other without problems. "t'es't" (outputs t'es't). You can't do this - 't'es't' (outputs error). However, you can escape them to do this. 't\'es\'t' (outputs t'es't).
QUOTE
Well I'm not too good at php but I've seen this problem loads. T_string refers to the $ whatever thing (see I don't know what even thats called).

That $ tells php that the string after it is in fact a variable.

test //string
$test //varible

 

 

 


Reply

demonlord
QUOTE(truefusion @ Jun 4 2008, 11:32 PM) *
Line 195 would be:
CODE
echo('<fieldset><legend>'.$user[username].''s Profile</legend>

You forgot to escape the single quote before the letter S. It should be:
CODE
echo('<fieldset><legend>'.$user[username].'\'s Profile</legend>


thanks that fixed it.

Reply

jlhaslip
Topic is resolved.

Please PM any moderator to continue this discussion. Until then, this topic is closed.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. php5 mysql_query t_string - 62.79 hr back. (1)
  2. unexpected t_string - 533.98 hr back. (1)
  3. unexpected t string - 699.39 hr back. (1)
  4. php "unexpected t_string" - 960.05 hr back. (1)
Similar Topics

Keywords : unexpected user php resolved

  1. Php Ftp Upload Form - Adding User Directory to PHP Upload Form - Help (1)
    Alright I am trying to have a PHP FTP Upload Form that allows the user to create the directory
    folder for where they want to upload there files to. example: Main Directory: vainsoft.com There
    directory: vainsoft.com/modeling or vainsoft.com/photography But I dont want them to be able to
    upload things into the main directory, only sub-directories, is that possible with this coding that
    I have: //uses $_FILES global array //see manual for older PHP version info //This
    function will be used to get the extension from the filename function get_extension($fi...
  2. Parse: Error Unexpected T_lnumber - php parse error when running script (4)
    Hi. I've just created a php script. The main object of the script is to delete some old files
    and replace it with a new file with some new content, effectively moving the contents from one file
    to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
    Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
    $a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
    include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&...
  3. Unexpected T_variable... - Help! (3)
  4. Script That Tracks The User Status - how can I track on or offline users? (4)
    long explaination: hey, I'm building a user profile site right now. And, I kinda know how to
    make a online/offline detector, but not totally sure. I know I can make a mysql database to track
    them, but how does it entrer the information? I could easily put in a field where when they login it
    sets them to online, but if they don't sign out, and just exit the browser, how can I tell.
    short: I want someone to tell me how to make a online/offline status detector, like they have here
    on trap17. I'd be thrilled if you can post to this, thanks, arcticsnpr...
  5. [mysql]get Id Of Loged In User? - (7)
    how to get the id number of the loged in user? my db is id. username. password. i have tryed a
    few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
    border="0" alt="ohmy.gif" />...
  6. Compare 2 List Of User Ids From Different Tables - (1)
    Hi all. I am trying to make a list out of 2 list. The first list is a complete list of users id
    from users table (List A) The Second list is of users id from another table (List /cool.gif"
    style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> I want to subtrack the user
    ids in List B from List A and make List C. Thanks in advance for any help /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Update: I looked up a old
    sql book i had and found some query examples. I tried the EXCEPT statement in mysql but it dont wor...
  7. Multiple Drop Down Lists ? - Multiple drop down lists to take user to new page (4)
    Hi everyone I was wondering if anyone could help. I want to create a page with multiple drop down
    lists and depending what the user selects decides the page they will be taken to. Sorry i havent
    explained this too well. Here is an example of what i want (link below) the user is also emailed a
    copy http://www.dermalogica.com/SpeedMappingOnl...US®ion=B I have searched the web and come
    close but nothing does it right I would be extremely greatful if anyone could help! Thanks ...
  8. Directing To A User To Specific Page First Time Only - (3)
    I make a signup page. I want that when someone signups and login for first time..then he is directed
    to the page X automatically. but after that it is redirected to Page Y always... Its pretty simple
    thing to do but im not understanding how i can make the script to identify that a person has logged
    in for first time ... anyhelp would be so welcome. Thanks....
  9. Password Strength / User Availablity Scripts ? - (2)
    many of u guys would already have noticed that now a days , on most of the websites , when some one
    sign in...as he puts his desired username in the textbox , the page shows that it is not available
    or it is available...without pushing any button etc.. and the second thing , when some one writes
    the password , on the same screen , it shows that password is weak or password is strong... i think
    it is done with php ... can some one give me a link to any page where i can access these scripts ?
    or some one can help me regarding this ?? Thanks for helping always....
  10. Unexpected $ Where There Aren't Any - (7)
    I am getting this message when testing a script I made: QUOTE Parse error: parse error,
    unexpected $ in /home/globa38/public_html/forum/mods/phpbb_fetch_all/news/forumnews.php on line
    159 On line 159, which is the last line in that file, I can only see this: CODE ?>
    What's the problem, and how can I fix it? /unsure.gif' border='0'
    style='vertical-align:middle' alt='unsure.gif' /> ...
  11. Parse Error - unexpected $ (1)
    i have this code CODE <?php if($_POST['user']=="" or
    $_POST['pass']=="" or $_POST['host']==""
    or $_POST['root']=="" or
    !isset($_POST['run'])){  print('<form method=post
    name=form>');  print('FTP username <input type=\'text\'
    name=user value=""><br>');  print('FTP password <input
    type=\'password\...
  12. Cleaning User Input With Regex - (1)
    As anyone who works with user input knows, not everyone who submits information makes it look
    proper. One one of my web forms, I parse all the needed fields that I wish to be title cased; their
    name, address, city, etc. I use this to perform this action, which works nicely: PHP Code: CODE
    $string = ucwords(strtolower($string)); This fixes the input if
    the user types in all caps or all lowercase. There is a problem I have been noticing about those who
    enter a generation after their name, such as "Bill Warner III". The above functio...
  13. Unexpected "$" Sign On Last Line Of File - even if i change the line nos it's there (3)
    I am trying to create a file which send mail after a user has filled in the appropiate fields in a
    form. It checks to see whether the required fields are full, writes some mail headers and sends it.
    When I check to see if the code works, I get this error: QUOTE(affliates.cmat) Parse error:
    parse error, unexpected $ in /home/cmatcme/public_html/affliates.cmat on line 203 The
    funny thing is that regardelss of how long I make the file, the file always appear on the final
    line, whether I leave it blank or just put ?> . I understand that these errors ca...
  14. Unexpected $ - what does it mean (9)
    You see I have a most intresting problem, basicaly I get the following error: QUOTE Parse error:
    parse error, unexpected $ in /path/result.php on line 99 Now normaly when I have problems
    I go to line 99 and add a ; or a " or something the problem is in my file line 99 is , CODE
     <tr bgcolor="#FFFFFF">    <td width="25" height="5"
    background="images/q3.png"> </td>    <td height="25"
    align="right" valign="top" background="images/bot.png"><span cla...
  15. User Login System With Setcookies - (13)
    a friend of mine is quite good at php and told me not to use sessions and to use setcookie im not
    sure how to use setcookie to make a user authentication system and was wondering if anyone here know
    a tutorial on how to do it...
  16. Php Login Script - Removing the login field once the user logs in (18)
    Hey everyone. I have a login script that i know works. My question is that on my main page, it have
    a form to allow the user to log in. What i want it to do is that once the user logs in, the form
    disappears and the users data (aka username) is displayed where the form was. At the moment i cant
    get it to work. Below is my code. CODE <div id="loginMenu">  <?php    if
    ($logged_in == 1)    {  ?>     <!-- User information -->  <?php
        }//if     else     {  ?>     <form action="<?php echo &...
  17. Create A Windows User Account - (1)
    hi, i am making an online registration scheme for my website for some webspace. i have got every
    thing sorted out exsept for one thing. to acces the ftp service and upload files to there user space
    i need to create a user account on the server for that user. is there a way to create a user account
    on a windows operating system with php 5 installed. thanks, kvarnerexpress ...
  18. User Log-in - PHP question (2)
    Hello all, I am a PHP n00b. I have read the Login page post, which is over my head. I was hoping
    someone could explain a concept to me more in layman's terms. This is what I hope to do - I want
    to go to my url (www.xyzblah.com) and have it automatically prompt for either a username and
    password, or just a password. After the correct credentials are supplied, go to the regular
    index.html. Any help you could give me is appreciated. Thanks....



Looking for unexpected, t, string, user, php

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for unexpected, t, string, user, php

*MORE FROM TRAP17.COM*
advertisement



Unexpected T_string In User.php [resolved]



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE