Parse error: syntax error, unexpected T_VARIABLE

Discussion in 'PHP' started by nastynappy, Feb 1, 2008.

  1. #1
    Parse error: syntax error, unexpected T_VARIABLE in D:\Softwares\Setups\xampp\htdocs\linkexchangesystem\install\sql\queries.php on line 48


    
    on line 47      $set_config = "INSERT INTO `config` (`code`, `url`, `title`, `require_recip`, `adscode`, `showads`, `nlatest`, `nfeatured`, `showfeatured`, `showlatest`) VALUES
    on line 48      ('<a href="$_SESSION['form_url']" title="$_SESSION['form_title']">$_SESSION['form_title']</a>', '.$_SESSION['form_url'].', '.$_SESSION['adtitle'].', 'n', '', 'n', 5, 5, 'y', 'y');";
    
    PHP:
     
    nastynappy, Feb 1, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Hello,

    It's because of the
    "
    Code (markup):
    in
    title="$_SESSION
    Code (markup):
    . You should escape and "'s within a string using a backslash (\) so it becomes \"

    Jay
     
    jayshah, Feb 1, 2008 IP
  3. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    great, now this error :
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Softwares\Setups\xampp\htdocs\linkexchangesystem\install\sql\queries.php on line 48

    $set_config = "INSERT INTO `config` (`code`, `url`, `title`, `require_recip`, `adscode`, `showads`, `nlatest`, `nfeatured`, `showfeatured`, `showlatest`) VALUES
    ('<a href=\"$_SESSION['form_url']\" title=\"$_SESSION['form_title']\">$_SESSION['form_title']</a>', '.$_SESSION['form_url'].', '.$_SESSION['adtitle'].', 'n', '', 'n', 5, 5, 'y', 'y');";
    PHP:
     
    nastynappy, Feb 1, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    $_SESSION['form_url'] must be {$_SESSION['form_url']}, enclose them all in curly braces { }

    Jay
     
    jayshah, Feb 1, 2008 IP
  5. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #5
    Just use,

    
    $set_config = "INSERT INTO `config` (`code`, `url`, `title`, `require_recip`, `adscode`, `showads`, `nlatest`, `nfeatured`, `showfeatured`, `showlatest`) VALUES
    ('<a href=".$_SESSION['form_url']." title=".$_SESSION['form_title'].">".$_SESSION['form_title']."</a>', '".$_SESSION['form_url']."', '".$_SESSION['adtitle']."', 'n', '', 'n', 5, 5, 'y', 'y');";
    
    PHP:
     
    HuggyStudios, Feb 1, 2008 IP
  6. jorgy

    jorgy Peon

    Messages:
    611
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm fairly certain that the problem is that:

    <a href=".$_SESSION[form_url]." instead of <a href=".$_SESSION['form_url]."

    T_ENCAPSED_AND_WHITSPACE is almost always a problem dealing with quotations
     
    jorgy, Feb 1, 2008 IP
  7. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you huggy studio, you code worked, +rep for you :)
     
    nastynappy, Feb 1, 2008 IP
  8. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    no wait, it doesnt work.
    when i write this code:

    
    echo 
        $_SESSION['stepname'] .   
    	$_SESSION['form_dbhost'] .  
    	$_SESSION['form_dbuser'] .  
    	$_SESSION['form_dbpass'] .
    	$_SESSION['form_dbname'] . 
    	$_SESSION['form_title'] .   
    	$_SESSION['form_url'].    
    	$_SESSION['form_email'] .
    	$_SESSION['form_username'].
    	$_SESSION['adminuser'].
    	$_SESSION['adminpass']
    	;
    
    
    $set_config = "INSERT INTO `config` (`code`, `url`, `title`, `require_recip`, `adscode`, `showads`, `nlatest`, `nfeatured`, `showfeatured`, `showlatest`) VALUES
    ('<a href=".$_SESSION['form_url']." title=".$_SESSION['form_title'].">".$_SESSION['form_title']."</a>', '".$_SESSION['form_url']."', '".$_SESSION['adtitle']."', 'n', '', 'n', 5, 5, 'y', 'y');";
    
    
    echo $set_config;
    
    PHP:

    it gives this output :

    
    Admin Infohellohttp://xyz.comadmin@pzzz.comtesttestasdasINSERT INTO `config` (`code`, `url`, `title`, `require_recip`, `adscode`, `showads`, `nlatest`, `nfeatured`, `showfeatured`, `showlatest`) VALUES ('', '', '', 'n', '', 'n', 5, 5, 'y', 'y');
    
    Code (markup):
    so, this code isnt parsing the session variables, while the session variables are already defined..
    that means , its an incorrect code..
    can anyone else help me please?


    Edited:


    Never mind, i fixed it myself..
    thanks for help though..
     
    nastynappy, Feb 1, 2008 IP
  9. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #9
    nastynappy:

    For echo, use the ',' to concatenate values rather than '.'. It's marginally quicker
     
    Danltn, Feb 2, 2008 IP