Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.php

Status
Not open for further replies.

elliott1

New Member
Messages
31
Reaction score
0
Points
0
the above comes up when trying to create a user using a php script the script is below where is says ther error is in:

<?php
$server = "localhost"; // server to connect to.
$database = "xxxxxx"; // the name of the database.
$db_user = "xxxxxx"; // mysql username to access the database with.
$db_pass = "xxxxxx; // mysql password to access the database with.
$table = "users"; // the table that this script will set up and use.
?>

i use this instead of having to type out each personal detail, below is the script to create user:

<?php
include("xxxxx.php");
// connect to the mysql server
$link = mysql_connect("$server", "$db_user","$db_pass")
or die ("Could not connect to mysql because ".mysql_error());
// select the database or table?
mysql_select_db("$table")
or die ("Could not select database because ".mysql_error());
// check if the users is taken
$check = "select id from $table where Users = '".$_POST['users']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $users is already taken.<br>";
echo "<a href=register.html>Try again</a>";
exit;
} else {
// insert the data
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."',
'".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());
// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=main_login.html>log in</a>";
}
?>

Thanks everyone for your help :biggrin:
 

alfred

New Member
Messages
87
Reaction score
0
Points
0
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

Well, you look at more recent php coding for this.

PHP:
<?php
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
    or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');


?>

I tried the older version (you way), the same way you did, and it yielded me the same error. You are trying PHP4 in a PHP5 environment, and we all have to update our scripts. Visit http://us.php.net/manual/en/ for more help.
 
Last edited:

elliott1

New Member
Messages
31
Reaction score
0
Points
0
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

:mad: it still doesnt work i dont know what php am using spend hours trying to fix it , do i need to upgrade my php account?
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

PHP:
<?php
$server = "localhost"; // server to connect to.
$database = "xxxxxx"; // the name of the database.
$db_user = "xxxxxx"; // mysql username to access the database with.
$db_pass = "xxxxxx; // mysql password to access the database with.
$table = "users"; // the table that this script will set up and use.
?>

$db_pass = "xxxxxx; // mysql password to access the database with.

This line in your code is missing a ", it should be:
$db_pass = "xxxxxx"; // mysql password to access the database with.
 

elliott1

New Member
Messages
31
Reaction score
0
Points
0
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

i have already changed the above , but thanks , still doesnt work though :dunno::dunno::dunno::dunno:
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

Are you receiving the same error? Also it usually tells you what line the error is on. Can you paste the line that the error is on?
 

elliott1

New Member
Messages
31
Reaction score
0
Points
0
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

i get a differnt error but it says on line 9:

<?php
include ("config.php");
////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
//
connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db("$mysql_database",$link) or die ("could not open db".mysql_error());

thanks
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

It needs to be:
PHP:
<?php
include ("config.php");
////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
//connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db("$mysql_database",$link) or die ("could not open db".mysql_error());
 

elliott1

New Member
Messages
31
Reaction score
0
Points
0
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

THANKS! again but now it says there a error on line 12 :mad:

<html>
<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
if(isset($todo) and $todo=="post"){
$status = "OK";
$msg="";
// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}
if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
$msg=$msg."Userid already exists. Please try another one<BR>";
$status= "NOTOK";}
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Re: Parse error: syntax error, unexpected T_STRING in /home/xxxxxx/public_html/xxxx.p

Not really sure where you're getting this script from...
Change
PHP:
<html>
<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
if(isset($todo) and $todo=="post"){
$status = "OK";
$msg="";
// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}
if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
$msg=$msg."Userid already exists. Please try another one<BR>";
$status= "NOTOK";}
TO
PHP:
<html>
<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?php
if(isset($todo) and $todo=="post"){
$status = "OK";
$msg="";
// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}
if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
$msg=$msg."Userid already exists. Please try another one<BR>";
$status= "NOTOK";}
 
Last edited:
Status
Not open for further replies.
Top