Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unexpected T_VARIABLE where data

Status
Not open for further replies.

verbatim1

Programmer
Apr 18, 2005
58
US
I can't find the solution in my php editor.

The error starts at the 1st line of data :
Code:
 $data["dbType"] = "mysql";
can someone tell me where my error is please?

Code:
<?php 
  function post_it($datastream, $url) {

$url = preg_replace("@^[URL unfurl="true"]http://@i",[/URL] "", $url); 
$host = substr($url, 0, strpos($url, "/")); 
$uri = strstr($url, "/");
$reqbody = ""; 

      foreach($datastream as $key=>$val) { 
          if (!is_empty($reqbody)) $reqbody.= "&"; 
      $reqbody.= $key."=".urlencode($val); 
      }

$contentlength = strlen($reqbody); 
     $reqheader =  "POST $uri HTTP/1.0\r\n". 
                   "Host: $host\n". "User-Agent: PostIt\r\n". 
     "Content-Type: application/x-[URL unfurl="true"]www-form-urlencoded\r\n".[/URL] 
     "Content-Length: $contentlength\r\n\r\n". 
     "$reqbody\r\n";

$socket = fsockopen($host, 80, $errno, $errstr); 

if (!$socket) { 
   $result["errno"] = $errno; 
   $result["errstr"] = $errstr; 
   return $result; 
} 

fputs($socket, $reqheader); 

while (!feof($socket)) { 
   $result[] = fgets($socket, 4096); 
} 

fclose($socket); 

return $result; 

} 
?>

<? php

  $data["dbType"] = "mysql";
  $data["dbHost"] = "localhost";
  $data["dbUser"] = "mem";
  $data["dbPass"] = "letmein";
  $data["dbName"] = "mel";
  $data["dbPrefix"] = "mem_com_-_mel";
  $data["dbPersistent"] = "false";
  
  $result = post_it($data, " [URL unfurl="true"]http://www.mem.com/userz/mel/admin.php?");[/URL] 

  if (isset($result["errno"])) { 
    $errno = $result["errno"]; 
    $errstr = $result["errstr"]; 
    echo "<B>Error $errno</B> $errstr"; 
    exit; 
  } else { 

    for($i=0;$i< count($result); $i++) echo $result[$i]; 

  } 

?>
 
Quite often when you get that error, if you check the lines before the one it points to, you will find an error. In your case, you have a space in your opening PHP tag. You wrote:
Code:
<? php
when it should be
Code:
<?php
You also reference the function is_empty():
Code:
if (!is_empty($reqbody)) $reqbody.= "&";
The function you want is empty():
Code:
if (!empty($reqbody)) $reqbody.= "&";

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top