473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

syntax error, unexpected T_STRING in /home/allummfa/public_html/Vars.inc on line 8

14 New Member
Hi all,

I'm having trouble with mysql.
I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website that directs to Auth.php.
The code for this is below:

<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/

if (!isset($_SERVE R['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="family pics"');
header('HTTP/1.0 401 Unauthorized');
echo 'This webpage requires athentication!' ;
exit;
}

else{
include("Vars.i nc");
$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($ host,$user,$pas sword)or die;
echo 'Couldn’t connect to server.';
$db = mysql_select_db ($database,$con nection)or die;
echo 'Couldn’t select database.';
$sql = "SELECT user_name FROM valid_user WHERE user_name = ‘$user_name' AND password = md5(‘$user_pass word’)";
$result = mysql_query($sq l)or die;
echo 'Couldn’t execute query.';
$num = mysql_num_rows( $result);
if ($num < 1)
{

echo 'The User Name or Password you entered is not valid.';
exit;

}
}
include("family pics.inc");




?>

My problem is I now cannot get the mysql query portion of my coding to work. When I enter the username and password in the login window that pops up, I get the error "Parse error: syntax error, unexpected T_STRING in /home/allummfa/public_html/Vars.inc on line 8".

I'm actually learning php from a book but i dont have much material to learn mysql. The database is created by my web hosting company called UserAccount. The scripts I have used to create the database table and store information needed by the php mysql functions are stored in a file called Vars.inc. This file is located in my html public folder, alongside my html and php files. The contents of Vars.inc are below:

<?php

$host = "localhost" ;
$user = "myusername ";
$password = "mypassword ";
$database = "UserAccoun t";

CREATE TABLE valid_user (user_name CHAR(25) NOT NULL, password CHAR(25) NOT NULL, create_date DATE NOT NULL, PRIMARY KEY(user_name)) ;


?>

I've been researching in google and tried a few changes with no joy.
Can anyone see whats wrong in the Vars.inc file? Should I really use the .inc extension?
I have entered an "include" command in my Auth.php file pointing towards Vars.inc. I assume that is ok.
Help!
Dec 19 '07 #1
6 2620
code green
1,726 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. unexpected T_STRING in /home/allummfa/public_html/Vars.inc on line 8
This is exactly what it says on the tin. A syntax error in Vars.inc on line 8.
If shown is the true contents of Vars.inc, the error occurs at CREATE TABLE. PHP does not know what this means.
You need to use the same mysql() functions and syntax used in Auth.php.
Dec 20 '07 #2
goodguyjam
14 New Member
Expand|Select|Wrap|Line Numbers
  1. unexpected T_STRING in /home/allummfa/public_html/Vars.inc on line 8
This is exactly what it says on the tin. A syntax error in Vars.inc on line 8.
If shown is the true contents of Vars.inc, the error occurs at CREATE TABLE. PHP does not know what this means.
You need to use the same mysql() functions and syntax used in Auth.php.

Ok thanks. I came across a couple sites that teaches a little mysql and i've amended my script as a lot were missing. I no longer get syntax errors.
But the snippets of info I get from the internet has left me confused. The Vars.inc code allows me to create a database table and also the lines in my code that contains the $host, $user and $password should represent my server's logins so the the php script can connect to the database. Am I right?
After which php does a query to match the user's logins with those in the database table, correct?
If this is the case where in the database table script do I store the user's logins (the table is called valid_user) so that when that user logs in via my website, he gets access to the restricted webpage? In the meantime I had tested the script by attempting to log in via the website just using random characters and I got the error generated from the Auth.php file (not from the Vars.inc file): "Could'nt connect to server". It appears the script was not even connecting successfully, let alone doing a query?
Am I missing something? The code is below. I hope you can shed some light. The Auth.php file which you have seen already is the same. Also is the .inc extension for the Vars.inc file correct for this application? I think I'm close to making all this finally work...help.



<?php

$host = "localhost" ;
$user = "my server's username";
$password = "my server's password";
$database = "UserAccoun t";

$connection = mysql_connect($ host,$user,$pas sword);
if (!$con)
{
die('Oh no I cannot connect!: ' . mysql_error());
}


/*Create table in
useraccount database*/

mysql_select_db ($database, $connection);
$sql = "CREATE TABLE valid_user
(
user_name varchar(25) NOT NULL, password varchar(25) NOT NULL, PRIMARY KEY ( 'user_name' ))";

mysql_query($sq l,$connection);
mysql_close($co nnection);
?>
Dec 22 '07 #3
code green
1,726 Recognized Expert Top Contributor
that contains the $host, $user and $password should represent my server's logins so the the php script can connect to the database. Am I right?
Yes
After which php does a query to match the user's logins with those in the database table, correct?
Your connection function connects to the mysql server.
Then you need to connect to the database.
Then you can query any table in the database.
If this is the case where in the database table script do I store the user's logins (the table is called valid_user) so that when that user logs in via my website, he gets access to the restricted webpage?
The users log in details are generally stored in a table specifically for that purpose.
So a web form is required where potential users can enrol.
After submit, this form calls a script that inserts the users details in to the table.
Your log in script querys this table checking the log in details against the data stored
In the meantime I had tested the script by attempting to log in via the website just using random characters and I got the error generated from the Auth.php file (not from the Vars.inc file): "Could'nt connect to server". It appears the script was not even connecting successfully, let alone doing a query. Am I missing something??
This is fromAuth.php. Hopefully you can see your mistake
[PHP]$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($ host,$user,$pas sword)or die;[/PHP]
The connection function must contain the host address,user name, password
of the MySql server particular to the database you are connecting to.
Then you need mysql_select_db ('database name') to actually connect to the database.
Hope this points you in the right direction
Dec 24 '07 #4
goodguyjam
14 New Member
Yes
Your connection function connects to the mysql server.
Then you need to connect to the database.
Then you can query any table in the database.

The users log in details are generally stored in a table specifically for that purpose.
So a web form is required where potential users can enrol.
After submit, this form calls a script that inserts the users details in to the table.
Your log in script querys this table checking the log in details against the data stored

This is fromAuth.php. Hopefully you can see your mistake
[PHP]$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($ host,$user,$pas sword)or die;[/PHP]
The connection function must contain the host address,user name, password
of the MySql server particular to the database you are connecting to.
Then you need mysql_select_db ('database name') to actually connect to the database.
Hope this points you in the right direction

Ok thanks for this.
I would like to manually code in the usernames and passwords for now, as this is for a family website so I dont really want the public registering online to see my photos. I will just code in my friends' logins. I got the php coding from a book but that book does'nt say much on mysql hence my problems.
Anyway I sort of understood this line: "$connectio n = mysql_connect($ host,$user,$pas sword)or die". That is why I included these lines: "
$host = "localhost" ;
$user = "allummfa_goodg uy";
$password = "my server's password";
$database = "UserAccoun t";
Where allummfa_goodgu y is the username I chose when the mysql database was set up by the webhosting wizard (which is different from the username I use to login to the control panel of my web hosting site). UserAccount is the actual name of the database. The password is what I chose for the mysql database.

But now I have removed these lines to hopefully simplify things and now all my coding is as below:

<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/

if (!isset($_SERVE R['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Image gallery"');
header('HTTP/1.0 401 Unauthorized');
echo 'Sorry, this page requires authentication! ';
exit;
}

else{

$user_name = trim($_SERVER[PHP_AUTH_USER]);
$user_password = trim($_SERVER[PHP_AUTH_PW]);
$connection = mysql_connect(" localhost","all ummfa_goodguy", "password for the mysql database")or die;
echo 'Couldnt connect to server.';
$db = mysql_select_db ("UserAccount", $connection)or die;
echo 'Couldnt select database.';

$user_name = "papa";
$user_password = "mama";

$sql = "SELECT user_name FROM valid_user WHERE user_name = $user_name AND password = md5($user_passw ord)";
$result = mysql_query($sq l)or die;
echo 'Couldnt execute query.';
$num = mysql_num_rows( $result);
if ($num < 1)
{

echo 'The User Name or Password you entered is not valid.';
exit;

}
}
include("imageg allery.inc");
?>

I figure the line below should allow the script to connect to the server:
$connection = mysql_connect(" localhost","all ummfa_goodguy", "mysql database password")or die;

This line below should allow the script to select the database:
$db = mysql_select_db ("UserAccount", $connection)or die;

These lines below should allow the script to query the table:
$sql = "SELECT user_name FROM valid_user WHERE user_name = $user_name AND password = md5($user_passw ord)";
$result = mysql_query($sq l)or die;

Note that valid_user is the name of the table.
And finally, this is the part I'm not sure of, how to manually code in my friends' username and password so that they can login on my website. I have attempted this by using these lines below in my complete coding:

$user_name = "papa";
$user_password = "mama";

Also note that the valid_user table in the database contains these fields:

user_name varchar(15)
password varchar(15)

Armed with all these scripts, things should be working but guess what, I still get the "could'nt connect to server" message.
My webhosting tech support says the server and database are ok.
I appreciate your help so far.
It looks like i'm still missing something.....
Dec 26 '07 #5
code green
1,726 Recognized Expert Top Contributor
things should be working but guess what, I still get the "could'nt connect to server" message.
Do you mean you see this
Expand|Select|Wrap|Line Numbers
  1. 'Couldnt connect to server.';
Well, this is coming from this piece of code and you will see it even if the database connection is succesful
[PHP]$connection = mysql_connect(" localhost","all ummfa_goodguy", "password for the mysql database")or die;
echo 'Couldnt connect to server.';
$db = mysql_select_db ("UserAccount", $connection)or die;
echo 'Couldnt select database.';[/PHP]Because you are using the echo command to output this string every time.
I think you mean [PHP]$connection = mysql_connect(" localhost","all ummfa_goodguy", "password for the mysql database")
or die('Couldnt connect to server.');
$db = mysql_select_db ("UserAccount", $connection)
or die('Couldnt select database.');[/PHP]
Dec 27 '07 #6
goodguyjam
14 New Member
Do you mean you see this
Expand|Select|Wrap|Line Numbers
  1. 'Couldnt connect to server.';
Well, this is coming from this piece of code and you will see it even if the database connection is succesful
[PHP]$connection = mysql_connect(" localhost","all ummfa_goodguy", "password for the mysql database")or die;
echo 'Couldnt connect to server.';
$db = mysql_select_db ("UserAccount", $connection)or die;
echo 'Couldnt select database.';[/PHP]Because you are using the echo command to output this string every time.
I think you mean [PHP]$connection = mysql_connect(" localhost","all ummfa_goodguy", "password for the mysql database")
or die('Couldnt connect to server.');
$db = mysql_select_db ("UserAccount", $connection)
or die('Couldnt select database.');[/PHP]
Yes you are right, I did miss that.
At last the authentication works, after a minor tweak of the SELECT line!
I can apply this on my website now.
Thanks for all your help.
I'l come back if any problems in the future.
Dec 29 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
489
by: Ben Allen | last post by:
Hi, Im currently getting the error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/midwestm/public_html/support/tutorials.php on line 15. When running the script below, I believe the error has only started to occur since we made the move to a server with global variables switched off. <?php ob_start(); ?>
4
22159
kestrel
by: kestrel | last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on. Heres what i have <?php if(isset($_GET)) { echo "<div id="visible">"; echo "<span onclick="swapform()">Log In Form</span>"; echo "</div>"; echo "<div id="theform" style="visibility: hidden">";
0
866
by: badkitty63 | last post by:
I am getting this error Help!!!!!! Parse error: syntax error, unexpected T_STRING in /home/desertr3/public_html/includes/languages/english/shipping.php on line 18 I am trying to add shipping information to the front page.This is what I entered includes/languages/english/shipping.php define('TEXT_INFORMATION', 'If you buy things from us we will send them to you. the more you buy the more boxes you will get in the mail and stuff.'); ...
36
8010
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My shortcomings will soon become apparent. I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main "projects" file, and 2 detail files, one for piping and one for equipment. Each of these files will have...
5
2495
by: goodguyjam | last post by:
Hi I'm trying to apply user authentication with HTTP on my site but i get the above error. Can anyone say whats wrong?? I cant figure it out. Here's my code below: <?php /* Program: Auth.php * Desc: Program that prompts for a user name and * password from the user using HTTP authentication. * The program then tests whether the user * name and password match a user name and password * pair stored...
10
2324
by: goodguyjam | last post by:
Hi again. I now get the above error with the exact same code as in my previous question. All I did was to rearrange the lines...no code changes...help! To assist you experts, line 11 contains this code - header(‘WWW-Authenticate: Basic realm=”secret section”’); Then when I remove the colon, I get a new error - syntax error, unexpected T_STRING in /home/allummfa/public_html/auth.php on line 11. This code is supposed to tell the web server to...
15
2095
by: micky125 | last post by:
Lo all, Ive been getting the error message Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/moneill/public_html/input.html on line 248 so ive checked me code over and over again but cant find whats wrong. So getting a annoyed I commented it to move on to next error but the same error message comes up. And when i remove the code completely the error message remains on...
10
5668
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject}</li>"; $page_set = get_pages_for_subject($subject);
14
5507
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on line 13 <? $username="XXXXXXXX"; $password="XXXXXX"; $database="XXXXXXXX";
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.