Free2Code
 
Time: 2008-11-21, 01:47am
tutorial failed
Subject: tutorial failed  ·  Posted: 2007-06-24, 06:12pm
Rank: ? (3)
Member #: 29640
PHP Login Script Tutorial



when i followed it and upload it to my website i get this error message. when i run the register.php

Parse error: parse error, unexpected T_VARIABLE in
/home/gamereli/public_html/db_connect.php on line 26


This is what my db_connect.php looks like

Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>GamerElites.com</title>
  6. </head>
  7. <body><?php
  8. //require the PEAR::DB classes.
  9. require_once 'DB.php';
  10. $db_engine 'mysql';
  11. $db_user 'myusername';
  12. $db_pass 'mypass';
  13. $db_host 'http://gamerelites.com';
  14. $db_name 'gamereli_user';
  15. $datasource $db_engine.'mysql'.
  16.               $db_user.'myusername'.
  17.               $db_pass.'mypass'.
  18.                $db_host.'http://gamerelites.com'.
  19.                 $db_name;gamereli_user
  20. $db_object DB::connect($datasourceTRUE);
  21. /* assign database object in $db_object, 
  22. if the connection fails $db_object will contain
  23. the error message. */
  24. // If $db_object contains an error:
  25. // error and exit.
  26. if(DB::isError($db_object)) {
  27.     die($db_object->getMessage());
  28. }
  29. $db_object->setFetchMode(DB_FETCHMODE_ASSOC);
  30. // we write this later on, ignore for now.
  31. include('check_login.php');
  32. ?>
  33. </body>
  34. </html>


i think that my problem is
$db_object = DB::connect($datasource, TRUE);


im not sure if i need to replace$datasouce with my actualy website link, followed by the name of my DB...

Sum1 please help me.

===========================
if you go to my website to test it dont forget to type this in after link... i have a temp .html tempalte up.. only so that people dont see my web structure.. use this to try it out

http://gamerelites.com/register.php
http://gamerelites.com/login.php
http://gamerelites.com/logout.php

PLease give me feedback

» Post edited 2007-06-25, 04:07pm by relpats_eht.

 
  Reply to this ·  Post link ·  Top
Subject: Re: tutorial failed  ·  Posted: 2007-06-25, 03:19am
Rank: ? (4821)
Member #: 3416
strange that db_connect.php would output html, but that might be what the tutorial tells you to do. anyway your problem is this line:

$db_name;gamereli_user


it's just not valid php. a couple other logic problems are:

1. $db_host is just a server name -- not a url. usually localhost works here.
2. $db_name is the name of the database you created, but 'gamereli_user' looks more like a user name to me. if you did name the database gamereli_user when you created it, then don't worry about this.
3. you should build the $datasource string using just the $db_* variables -- you don't need to use their values again. i don't remember the exact syntax for PEAR::DB, but i think it should look something like mysql://user:pass@localhost/dbname when you're done. you can use echo $datasource after you set up the variable to make sure it looks right.

hope that helps!

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: tutorial failed  ·  Posted: 2007-06-25, 08:46am
Rank: ? (3)
Member #: 29640
well gamereli_user is the name of my database.
this is what my code looks like actually.. i modified it last night after this post.
Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>GamerElites.com</title>
  6. </head>
  7. <body><?php
  8. //require the PEAR::DB classes.
  9. require_once 'DB.php';
  10. $db_engine 'mysql';
  11. $db_user 'myusernametoserver';
  12. $db_pass 'mypasstoserver';
  13. $db_host 'localhost';
  14. $db_name 'gamereli_user';
  15. $datasource $db_engine.'mysql'.
  16.               $db_user.'myusernametoserver'.
  17.               $db_pass.'mypasstoserver'.
  18.               $db_host.'localhost'.
  19.               $db_name;'gamereli_user'.
  20. $db_object DB::connect($datasourceTRUE);
  21. /* assign database object in $db_object, 
  22. if the connection fails $db_object will contain
  23. the error message. */
  24. // If $db_object contains an error:
  25. // error and exit.
  26. if(DB::isError($db_object)) {
  27.     die($db_object->getMessage());
  28. }
  29. $db_object->setFetchMode(DB_FETCHMODE_ASSOC);
  30. // we write this later on, ignore for now.
  31. include('check_login.php');
  32. ?>
  33. </body>
  34. </html>


I tried what u said.. didnt work.. i think i didnt write it correctly.. because i was gettign the same error.

IF you dont mind would you please just post a modified version of what u think it should look like.. AND THANKS SO MUCH. i apreciate your helpsmile


im also kinda curious about this.. require_once 'DB.php'; should this be require_once 'gamereli_user.php'; because gamereli_user is the name of by DB

» Post edited 2007-06-25, 04:01pm by relpats_eht.

 
  Reply to this ·  Post link ·  Top
Subject: Re: tutorial failed  ·  Posted: 2007-06-25, 03:59pm
Rank: ? (767)
Member #: 11085
Once again, your problem (as in, what is causing the error), is this line:
$db_name;'gamereli_user'.

You know what to do to fix it, I trust. If you don't, stare until the answer jumps out at you (hint: it has to do with punctuation).

However, even when you fix that, your code still will not work. As misterhaan has already said:
3. you should build the $datasource string using just the $db_* variables -- you don't need to use their values again. i don't remember the exact syntax for PEAR::DB, but i think it should look something like mysql://user:pass@localhost/dbname when you're done. you can use echo $datasource after you set up the variable to make sure it looks right.

If you need more help there than that, take another look at the tutorial, it says exactly what you should do.

On to your most recent question, require_once is a function which literally (sort of) takes another PHP file and inserts it in the place of the function call. DB.php is a file supplied by the PEAR add on to PHP which holds the database class. It is not necessary to use if you want MySQL, but it is necessary if you want to interface with MySQL with the PEAR::DB class (as you are and the tutorial suggests).

Also, please don't ask us to post the modified code. You don't learn anything by completing a project, you learn by whatever journey you take to get there. If you have a problem, I would advise looking up the error codes, thinking about the logic of your program, and reading the manual for a few hours to try to fix the problem on your own first, and if you don't have the answer by then, then coming to ask us. It is tedious and it is boring, but you will learn, eventually.

Lastly, and I am going way off topic here, keep in mind that, at least with programming, the road to understanding is full of long plateaus. You likely wont have the slightest idea what you are doing for months. Keep doing as I suggested anyway, and eventually, all at once, understanding will come via epiphany, likely at the oddest moment.

Oh yes, use code tags next time you post source, it makes code much easier to read (I have modified your posts this time around (and added more general formatting, out of boredom and desire to abuse my powers)).

» Post edited 2007-06-25, 04:08pm by relpats_eht.

- relpats_eht
 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons