Appcan Development Tip Exception syntax error, unexpected '] ' expecting t_string or t_variable or T

Source: Internet
Author: User
Tags parse error
Appcan Development Tip Error Syntax err, unexpected '] ', expecting t_string or t_variable or t_
1server.php
Date_default_timezone_set ("Asia/shanghai");
Header ("content-type:text/html; Charset=utf-8 ");
Require_once ("config.php");
?>


$request = $_get[' jsoncallback ');

SQL query Statements
$sql = "Select Id,bookname,pubdate,author from Td_book where tid=". $Id. ";
$query = mysql_query ($sql);
Assigning a value to a JSON array
while ($row =mysql_fetch_array ($query))
{
$demoData []=array (
' Tid ' = ' $row [' Id '] ',
' Subject ' = $row [' BookName '],
' Dateline ' = $row [' Pubdate '],
' Author ' = $row [' Author '],
);
}

Let JSON support Chinese UTF-8 encoding
Class json{

public static function encode ($STR) {

$code = Json_encode ($STR);

Return Preg_replace ("#\\\u ([0-9a-f]+?) {4}) #ie "," Iconv (' UCS-2 ', ' UTF-8 ', pack (' H4 ', ' \\1 ')) ", $code);

}

public static function decode ($STR) {

Return Json_decode ($STR);

}

}

JSON data returned to the client
echo $request. ' ('. Json_encode ($demoData). ') ';
Close the database
Exit
?>

2 page HTML



<title><br/></title>

























View the next 10 articles










3book.js

/**
* Example of client-server data interaction
*
*
*/

/**
* Server Address
*/
var bookhost = "http://localhost:1000/server.php?jsoncallback=?";

/**
* JS End base64 instantiation
*/
var b64 = new Base64 ();


/**
* Network Request transfer function
*
* @param {Object} URL server request address
* @param {Object} callback callback function
*/
function XmlHttp (url,callback) {
if (url = = ") {
Uexwindow.alert (' parameter error ', ' request address cannot be empty! ', ' return ');
}else{
$.getjson (Url,callback);
}
}

/**
* Get a list of posts
*/
function Getbooklist () {
Uexwindow.toast ("1", "5", "Data Loading ...", "0");

var url = bookhost;
XmlHttp (url,showlist);
}

/**
* Callback function to process the post data returned by the server side, displayed on the client
* JSON data returned by @param {Object} items server Side
*/
function Showlist (items) {
var forumobj = $ ("#book_list");
Forumobj.html (");

for (var i in items) {
var item = Items[i];

var tr = ';
var trheader = ';
var trtitle = ' +b64.decode (item.subject) + ';
var trotherinfo = ' ' +b64.decode (item.dateline) + ' +b64.decode (item.author) + '';
var trfooter = ';
tr = Trheader+trtitle+trotherinfo+trfooter;
Forumobj.append (TR);
}
Uexwindow.closetoast ();
}



Prompt error
Parse error:syntax error, unexpected '] ', expecting t_string or t_variable or t_num_string in D:\WWW\server.php on line 1 7

Solving!!!
The result I want to show is


------to solve the idea----------------------
First place:
$sql = "Select Id,bookname,pubdate,author from Td_book where tid=". $Id. ";
The last is a double quotation mark, which is obviously not grammatical, because except in quotation marks, the quotation marks must appear in pairs.
Now that you've turned his partner away, he's going to make you cry.

Second place:
' Tid ' = '$row [' Id '] ',
Single and double quotes in single quotes must be escaped, or PHP will not know what to enclose in quotation marks
The variables in single quotes are not valued, and obviously you don't meet the business requirements.
------to solve the idea----------------------
$query = mysql_query ($sql) or Die (Mysql_error ());
You see what's wrong.
------to solve the idea----------------------
No database selected No databases selected
You don't see the use of the mysq_select_db function in your config.php.
------to solve the idea----------------------
You did not choose the database, less mysql_select_db ("Tyshichang"); This sentence.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.