Jump to content

syntax error, unexpected '[', expecting ',' or ';'


longsack

Recommended Posts

I'm getting the following error message... maybe someone can help?

 

syntax error, unexpected '[', expecting ',' or ';' on line 4

 

I understand _POST is a superglobal.... I have tried $_POST, global $_POST and so on.....

If I remove the line "//" the form will load, however none of the info will be saved... also a simple $_POST will result in the form loading, however it don't save the info correctly (if at all)...

 

Can someone please look over all the code and let me know what I'm doing wrong... I'm still learning this stuff! :)

 

Thanks so much!

 

<?php
function deleteslashes( )
{
    global $GLOBALS['_POST'];
    if ( isset( $_POST ) )
    {
        while ( list( $key, $value ) = each( $_POST ) )
        {
            $GLOBALS['_POST'][$key] = str_replace( "|", "_", $_POST[$key] );
            $GLOBALS['_POST'][$key] = str_replace( "*", "_", $_POST[$key] );
        }
        return $_POST;
    }
}

ignore_user_abort( true );
require_once( "variables.php" );
ini_set( "memory_limit", "45M" );
ini_set( "max_execution_time", "300" );
$id = isset( $_GET['id'] ) ? $_GET['id'] : "Unknown";
$action = isset( $_POST['action'] ) ? trim( $_POST['action'] ) : "none";
if ( $id != "Unknown" )
{
    include( "header.php" );
    echo "<form method=post action=\"delete_user.php\"><table width=100% height=100% border=1 bordercolor=\"#999999\" cellpadding=3 cellspacing=0><tr class=menu><td colspan=2 height=20>Delete user</td></tr><tr><td align=center><b>Are you sure you want to delete this user?</b><br><br><br><input type=\"hidden\" name=\"id\" value=\"{$id}\"><input type=\"hidden\" name=\"action\" value=\"confirm\"><input type=\"submit\" name=b1 value=\"Proceed\" style=\"width: 150\">   <input type=\"button\" value=\"Close Window\" onClick=\"window.close()\" style=\"width: 150\"></td></tr></table></body></html>";
}
if ( $action == "confirm" )
{
    include( "header.php" );
    $id = isset( $_POST['id'] ) ? trim( $_POST['id'] ) : "";
    if ( file_exists( "{$scriptpath}/rotator/data/user.{$id}.info" ) )
    {
        @unlink( "{$scriptpath}/rotator/data/user.{$id}.info" );
    }
    if ( file_exists( "{$scriptpath}/rotator/data/{$id}.t" ) )
    {
        @unlink( "{$scriptpath}/rotator/data/{$id}.t" );
    }
    if ( file_exists( "{$scriptpath}/rotator/data/{$id}.posts" ) )
    {
        @unlink( "{$scriptpath}/rotator/data/{$id}.posts" );
    }
    $users_file = file_exists( "{$scriptpath}/rotator/data/users" ) ? file( "{$scriptpath}/rotator/data/users" ) : array( );
    $new_file = array( );
    $last = count( $users_file ) - 1;
    $last_ID = isset( $users_file[$last] ) ? rtrim( $users_file[$last] ) : 0;
    while ( list( $k, $v ) = each( $users_file ) )
    {
        if ( $k == $last )
        {
            break;
        }
        $v = trim( $v );
        $user_info = explode( "|", trim( $v ) );
        $user_id = isset( $user_info[0] ) ? $user_info[0] : "Unknown";
        if ( $user_id == $id )
        {
            continue;
        }
        $new_file[] = trim( $v );
    }
    $text = join( "", $new_file );
    $text .= "{$last_ID}";
    $f1 = fopen( "{$scriptpath}/rotator/data/users", "w" );
    fwrite( $f1, $text );
    fclose( $f1 );
    @chmod( "{$scriptpath}/rotator/data/users", 511 );
    echo "<table width=100% border=1 bordercolor=\"#999999\" cellpadding=3 cellspacing=0 height=\"100%\"><tr class=menu><td colspan=2 height=20 height=20>Done</td></tr><tr><td align=center valign=top><br><b>User has been deleted</b><br><br><input type=\"button\" value=\"Close Window\" onClick=\"window.close()\" style=\"width: 150\"></td></tr></table></body></html>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/98953-syntax-error-unexpected-expecting-or/
Share on other sites

The $_POST array is a superglobal array, which means it's available in all scopes without declaring it at as a global.

 

You have a function called deleteslashes(), but

a) you don't reference it in the rest of your code,

b) it doesn't delete any slashes from the values in the $_POST array

c) there is a built-in function stripslashes() that does this already

 

If you really want to strip all backslashes from the $_POST array use the array_map() function:

<?php
$_POST  = array_map('stripslashes', $_POST);
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.