Jump to content

Include file problems


genista

Recommended Posts

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?:

[code]

<?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");
}  

?>
[/code]

Edited by ryanlwh: Added the [code] block
Link to comment
Share on other sites

i spot two errors. there might be more
[code]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;
}[/code]
missing { after if (or extra } after return false;)


[code]////open the database
$mysqldb = mysql_select_db($mydb);
if(!mysqldb)
{
{$error = "Cannot open database";
return($error);
}[/code]
extra { before $error
Link to comment
Share on other sites

or replacing } with else
[code]
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;
}
[/code]
Link to comment
Share on other sites

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) [snapback]374431[/snapback][/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]
Link to comment
Share on other sites

"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
Link to comment
Share on other sites

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);
}

?>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

[code]<?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");
//}  

?>[/code]

EDIT - [b]Please[/b] use the CODE buttons to make your code easier to read. Indenting conditionals would be even better.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.