php compile error: unexpected t_string

Discussion in 'PHP' started by snowcap, Dec 10, 2011.

  1. #1
    Hello,

    
    $myData = $_REQUEST['data'];
    $xmltag = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
    print $xmltag;
    print '<mydata>';
    
    require('../DBtest.php');
    
    $host = '*******';
    $userid = '*******';
    $password = '*******';
    
    $db = mysql_perry_pconnect($host, $userid, $password);
    
    if() {
      echo 'Error: Could not connect to database. Please try again later.';
      exit;
    }
    
    $names = explode("|", $myData);
    $firstName = $names[0];
    $lastName = $names[1];
    
    $fullName = $firstName . " " . $lastName;
    
    $dbname = '7phpmysql7';
    $dbtest = mysql_perry_select_db($dbname);
    
    $query = "SELECT year_recorded, hours_slept FROM ajax_sleptdata WHERE fullname = " . $fullName . ";
    $result = mysql_query($query);
    $xml_element = "";
    
    if(!empty($result)) {
      $valid = "false";
      $numofresults = mysql_num_rows($result);
      
      if($numofresults > 0) {
        for($counter = 1; $counter <= $numofresults; $counter++) {
          $row = mysql_fetch_array($result);
          $dbfullname = $row['fullname'];
          $year = $row['year_recorded'];
          $hours = $row['hours_slept'];
          
          if($fullName == $dbfullname) {
            $valid = "true";
          }
          
           $xml_element =  "<personal_data><fullname>".$dbfullname."</fullname><year_recorded>".$year."</year_recorded><hours_slept>".$hours."</hours_slept><valid>".$valid."</valid></personal_data>";
          print $xml_element;
        }
      }
      
      print "</mydata>";
    }
    
    PHP:

    I have been playing with ajax and php. I'm connecting to a database, using a mysql query, and passing information from php to ajax, by printing out the data in a xml like this...

    print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
    PHP:
    In ajax I pull the data from the xml file and display the data in a table. When I compile the php file, I receive this error...

    I have been searching different forums, and find people with a similar problem, but none of it is relative enough to help me. Any thoughts? Thank you.
     
    snowcap, Dec 10, 2011 IP
  2. Karl-

    Karl- Greenhorn

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Try using:
    $xmltag = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>';
    Code (markup):
     
    Karl-, Dec 10, 2011 IP
  3. snowcap

    snowcap Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the response, but I still get the same error.
     
    snowcap, Dec 10, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    Are you sure that's the line throwing the error? (Usually you get a line number at the end of the error message.)
     
    Rukbat, Dec 10, 2011 IP
  5. sMe76

    sMe76 Peon

    Messages:
    8
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is probably not what casuses the error, but you have this line in your code: $dbfullname = $row['fullname']; but you don't retrive fullname from the DB.
    Try change it to: $dbfullname = $fullname; (since you get the fullname variable earlier in your code).

    Yeah. I noticed something else to:
    if() {
    echo 'Error: Could not connect to database. Please try again later.';
    exit;
    }

    try:
    if($db) {
    echo 'Error: Could not connect to database. Please try again later.';
    exit;
    }

    Start with these changes and we'll go from there...
     
    sMe76, Dec 11, 2011 IP