Jump to content


Photo

Include file problems


  • Please log in to reply
12 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 16 May 2006 - 08:42 PM

Hi guys,

I am getting the following error off the code below:

Parse error: parse error, unexpected $ in blah/blah on line 89.

I know this has got to be an open bracket or something like that but I cannot spot it for thelife of me.

ANy one got any ideas?:


<?php

function trimdata($formdata)
{
//Trim any leading or trailing spaces
//$formdata=form data array
foreach ($formdata as $key=> $value)
{
$new_array[$key] = trim($value);
}
return $new_array;
}

function check_password_length($formdata, $password, $minlen)
{
//check the password is the correct length
//$formdata = form data array
//$password = name of password field
//$minlen = minimum length of password field
if (strlen($formdata[$password]) < $minlen)
return false;
}
return true;
}

function confirm_password($formdata, $password, $password2)
{
//check the two paswords match

if ($formdata[$password1] === $formdata[$password2])
return true;
else 
return false;
}

function check_unique ($formvalue, $mydb, $myhost, $myuser, $mypass, $table, $field)
{
//Check to see if the value still exists in the database
//$formvalue = unique value to be checked

$error = "";


//Connect to the mysql server
$mysql = mysql_connect($myhost, $myuser, $mypass);
if(!$mysql)
{
$error = "cannot connect to the database host";
return($error);
}

////open the database
$mysqldb = mysql_select_db($mydb);
if(!mysqldb)
{
{$error = "Cannot open database";
return($error);
}

//Query table to see if $formvalue is unique
$myquery = "SELECT * FROM $users where $username = '$formvalue'";
$result = mysql_query($myquery);
{
$error = "Cannot run query";
return($error);
}

//Get number of records found, should be 0 if formvalue is unique
$unique = mysql_num_rows($result);
if ($unique > 0)
{
$error = $formvalue. "Already in use";
return($error);
}

//Return true if $formvalue is unique
return("true");
}  

?>

Edited by ryanlwh: Added the [code=auto:0] block

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 16 May 2006 - 08:51 PM

i spot two errors. there might be more
function check_password_length($formdata, $password, $minlen)
{
//check the password is the correct length
//$formdata = form data array
//$password = name of password field
//$minlen = minimum length of password field
if (strlen($formdata[$password]) < $minlen)
return false;
}
return true;
}
missing { after if (or extra } after return false;)


////open the database
$mysqldb = mysql_select_db($mydb);
if(!mysqldb)
{
{$error = "Cannot open database";
return($error);
}
extra { before $error
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 16 May 2006 - 08:53 PM

or replacing } with else
function check_password_length($formdata, $password, $minlen)
{
//check the password is the correct length
//$formdata = form data array
//$password = name of password field
//$minlen = minimum length of password field
if (strlen($formdata[$password]) < $minlen)
return false;
else
return true;
}


#4 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 16 May 2006 - 08:59 PM

Thanks! Changed those, but still the same unfortunatly, any other ideas.
Incidentally the line number that is erroring -(89), does not exist in this include file.

G

#5 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 16 May 2006 - 09:21 PM

i can't find any more, even tested it myself without errors
- are you sure it is that file you have the error report on now?

#6 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 16 May 2006 - 10:06 PM

I am testing this through the join form which calls this include file. When I navigate to the join form I get the error for the include file. Surely if it were an error on the join form it would say that, as opposed to showing an error on the include file?

G


[!--quoteo(post=374431:date=May 16 2006, 04:21 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 16 2006, 04:21 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i can't find any more, even tested it myself without errors
- are you sure it is that file you have the error report on now?
[/quote]


#7 dlowery

dlowery
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 May 2006 - 11:51 PM

"I ain't no ex-spurt, but..." if the error line is outside the code file chances are that there's a missing brace '{}' or parenthesis '()'. I use a code editor that lets you check this quickly. Put your cursor in front of the first opening brace, hit CTRL-M and it finds the closing brace. No matter how deep or complex and free of charge! And so on down the line. The editor has features like tidy, strip M$Word excesses, and things I haven't explored...it's great!

Google "HTML-Kit". There's a free version; look for it. There's probably some others in OSS and for linux. I just haven't looked.

Have fun!
dlowery

#8 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 17 May 2006 - 12:14 AM

you might have some errors in the script that includes it. you might want to post the corrected version of this one too.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#9 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 17 May 2006 - 09:55 AM

Hi guys,


I have just tested the include file on its own (whereas before I was running the join form and getting the error) and I get the same error so it must be in the include file...

I'll post it again with the changes I made last night:


<?php

function trimdata ($formdata)
{
//Trim any leading or trailing spaces
//$formdata=form data array
foreach ($formdata as $key=> $value)
{
$new_array[$key] = trim($value);
}
return $new_array;
}

function check_password_length($formdata, $password, $minlen)
{
//check the password is the correct length
//$formdata = form data array
//$password = name of password field
//$minlen = minimum length of password field
if (strlen($formdata[$password]) <$minlen)
return false;
else
return true;
}

function check_unique ($formvalue, $db, $dbhost, $dbuser, $dbpassword, $table, $field)
{
//Check to see if the value still exists in the database
//$formvalue = unique value to be checked

$error = "";
}


function insert_data($formdata)
{
//insert data into the users table
//$formdata = form array

//set up database connection
$error = "";
$myhost = "ipaddress";
$myuser = "username";
$mypass = "password";
$mydb = "database name";

//data to insert

$first_name = $formdata ['first_name'];
$last_name = $formdata ['last_name'];
$maiden_name = $formdata['maiden_name'];
$address_line1 = $formdata ['address_line1'];
$address_line2 = $formdata['address_line2'];
$town = $formdata['town'];
$county = $formdata['county'];
$postcode = $formdata['postcode'];
$daytime_phone = $formdata['daytime_phone'];
$evening_phone = $formdata['evening_phone'];
$email_address = $formdata['email_address'];
$date_ofbirth = $formdata['date_ofbirth'];
$wedding_date = $formdata['wedding_date'];
$number_ofguests = $formdata['number_ofguests'];
$wedding_venue = $formdata['wedding_venue'];
$wedding_area = $formdata['wedding_area'];
$username = $formdata['username'];
$info = $formdata['info'];

//encrypt the password
//$password =crypt ($password, "DWMXPHP");

//connect to the database
//connect to the server
$mysql = mysql_connect($dbhost, $dbuser, $dbpassword);
if(!Mysql)
{
$error = "Cannot connect to the database";
return($error);
{
//Open the database
$mysqldb = mysql_select_db($db);
if (!$mysqldb)
$error = "Cannot open Database";
return($error);
}

?>

#10 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 17 May 2006 - 06:25 PM

Am I missing a closing bracket at the end?

#11 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 17 May 2006 - 07:01 PM

Hi, you seem to have messed things up a bit again with some missing and som wrong brackets, please follow your first posted code and make the adjustments stated in the following posts and it will work.
I advice you to use a php editor that will highlight your syntax as you write, making opening and closing brackets match themselves. I recoment the totally free [a href=\"http://www.mpsoftware.dk/\" target=\"_blank\"]PHP Designer[/a] as a good freehand tool.

#12 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 22 May 2006 - 08:34 PM

Hi all,

Ok so I am really stuck now (and frustrated) this script is now giving me the following error and I have highlighted the line that is causing the error:

Parse error: parse error, unexpected T_ARRAY in /home/fhlinux245/h/blah.com/user/Includes/testinclude.php on line 38

Thanks,
G

<?php

function trimdata($formdata)
{
    //Trim any leading or trailing spaces
    //$formdata=form data array
    foreach ($formdata as $key=> $value)
    {
         $new_array[$key] = trim($value);
    }
    return $new_array;
}

function check_password_length($formdata, $password, $minlen)
{
    //check the password is the correct length
    //$formdata = form data array
    //$password = name of password field
    //$minlen = minimum length of password field
    if (strlen($formdata[$password]) <$minlen)
        return false;
    else
        return true;
}

function confirm_password($formdata, $password, $password2)
{
    //check the two paswords match

    if ($formdata[$password1] === $formdata[$password2])
        return true;
    else 
        return false;
}

//Connect to the mysql server
$mysql = mysql_connect($myhost, $myuser, $mypass);
[b]if(!$mysql)[/b]
{
    $error = "cannot connect to the database host";
    return($error);
}

////open the database
$mysqldb = mysql_select_db($mydb);
if(!mysqldb)
{
    $error = "Cannot open database";
    return($error);
}

//Query table to see if $formvalue is unique
$myquery = "SELECT * FROM $users where $username = '$formvalue'";
$result = mysql_query($myquery);
{
    $error = "Cannot run query";
    return($error);
}

//Get number of records found, should be 0 if formvalue is unique
$unique = mysql_num_rows($result);
if ($unique > 0)
{
    $error = $formvalue. "Already in use";
    return($error);
}
//Return true if $formvalue is unique
//return("true");
//}  

?>

EDIT - Please use the CODE buttons to make your code easier to read. Indenting conditionals would be even better.

#13 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 23 May 2006 - 04:26 PM

Any help on this would be greatly appreciated guys.

Thanks,

G




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users