Today, I met a php problem, ask my friends to help thanks

Source: Internet
Author: User
Tags parse error
Parse error:syntax error, unexpected t_encapsed_and_whitespace, expecting t_string or t_variable or t_num_string in E:\am p\apache\htdocs\prod\viewcat.php on line 22
Encountered this error, the internet did not find the answer, trouble you can help me solve ha, loyal thanks.
My Code:
Require ("config.php");

if (Isset ($_get[' id ') ==true) {
if (Is_numeric ($id) ==false) {
$error = 1;
}
if (Isset ($error) && $error ==1) {
Header ("Location:". $config _basedir. " /viewcat.php ");
}
else{
$validcat =$_get[' id '];
}
}
else{
$validcat = 0;
}
$sql = "SELECT * FROM Categories";
$result =mysql_query ($sql);
while ($row =mysql_fetch_assoc ($result)) {
if ($validcat = = $row [' id ']) {
echo " ". $row [' Cat '].
";

$entriessql = "SELECT * FROM Entries WHERE cat_id=". $validcat.
"ORDER by dateposted DESC;";
$entriesres =mysql_query ($entriessql);
$numrows _entries=mysql_nums_rows ($entriesres);

echo "
      ";
      if ($numrows _entries==0) {
      echo "
    • No entries!
    • ";
      }
      else{
      while ($entriesrow =mysql_fetch_assoc ($entriesres)) {
      echo "
    • ". Date (" D JS F Y G.ia ", Strtotime ($entriesrow [' dateposted ']))." -". $entriesrow [' Subject ']."
    • ";
      }
      }
      echo "
";
}
else{
echo "". $row [' Cat '].
";
}
}
Require ("footer.php");
?>


Reply to discussion (solution)

Do you want to mark the error line?

echo "". $row [' Cat '].
";
There's something wrong here, but I can't find the error.

The 1,MYSQL_FETCH_ASSOC function is case-sensitive. $row [' Cat '] cat is case-sensitive in the database?
2,MYSQL_FETCH_ASSOC can only return a row of arrays indexed by a field, mysql_fetch_array () is recommended.

$entriessql = "SELECT * FROM Entries WHERE cat_id=". $validcat. " ORDER by dateposted DESC; ";
There is a problem with this sentence, and a space is missing before ORDER by.
Change to the following should be possible.
$entriessql = "SELECT * FROM Entries WHERE cat_id=". $validcat. " ORDER by dateposted DESC; ";

$entriessql = "SELECT * FROM Entries WHERE cat_id=". $validcat.
"ORDER by dateposted DESC;";
Let's change to the bottom.

$entriessql = "SELECT * from entries WHERE cat_id= {$validcat} ORDER by dateposted DESC";

echo "{$row [' Cat ']}
"Try this.

$entriessql = "SELECT * FROM Entries WHERE cat_id=". $validcat.
"ORDER by dateposted DESC;";

The error is grammatical errors

Thank you for your help, I have to redo the blog once again, seemingly no problem, recently did not how on the forum, hope everyone understanding, thank you for your help

  • Related Article

    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.