www.webdeveloper.com
Results 1 to 5 of 5

Thread: parse errors

  1. #1
    Join Date
    Mar 2008
    Posts
    13

    parse errors

    I am getting various parse errors when I execute the below script, called createpage.php. I am trying to generate a completly new .php file from content retrieved from the database. When I call the createpage.php, I get parse errors on the following lines. I know it has to do something with my using of ' '...but I don't know how to get it working. What am I doing wrong, do I have to use stripslashes or an escape character or something? Code I am inserting to a new file is in italics--lines that are giving me errors are in bold...



    <?php
    session_start();
    if(!isset($_SESSION['username']) || !isset($_SESSION['sid']) ||!isset($_SESSION['ip'])) {
    header("Location: login.php");
    exit;
    }
    include("connection.php");
    $usershort = $_SESSION['username'];
    $result = mysql_query("SELECT groupnum FROM users WHERE username = '$usershort'");
    while($row=mysql_fetch_array($result)) {
    $group = $row["groupnum"];}

    $titleofpage = $_POST['titleofpage'];

    $query = "INSERT INTO group".$group."_pathway (title, content1, content2, content3) VALUES ('$titleofpage', 'This is some default content for content block 1', 'This is some default content for content block 2', 'This is some default content for content block 3')";

    // Perform the SQL query on the database.
    $result = mysql_query($query);

    $result2 = mysql_query("SELECT page FROM group".$group."_pathway WHERE title = '$titleofpage'");
    while($row2=mysql_fetch_array($result2)) {
    $pagenum = $row2["page"];}


    /*
    ** open file for writing
    */
    $sql = "SELECT page FROM group".$group."_pathway WHERE title=$titleofpage";
    $qry = mysql_query($sql);
    $filename = "group".$group."_page".$pagenum.".php";
    if(!($myFile = fopen($filename, "w")))
    {
    print("Error: ");
    print("'$filename' could not be created\n");
    exit;
    }

    $data = '<HTML><HEAD><link rel="stylesheet" type="text/css" href="group1_main.php"></HEAD><?php
    include("connection.php");
    $usershort = $_SESSION['username'];
    $result = mysql_query("SELECT groupnum FROM users WHERE username = '$usershort'");
    while($row=mysql_fetch_array($result)) {
    $group = $row["groupnum"];}
    $titleofpage = mysql_query("SELECT title FROM group1_pathway");
    $titleofpage2 = mysql_query("SELECT title FROM group1_pathway");
    $row5=mysql_fetch_array($titleofpage2);
    $display_title2 = $row5["title"];
    $pagenum = mysql_query("SELECT page FROM group1_pathway ORDER BY page");
    $content1 = mysql_query("SELECT content1 FROM group1_pathway WHERE title = '$display_title2'");
    $content2 = mysql_query("SELECT content2 FROM group1_pathway WHERE title = '$display_title2'");
    $content3 = mysql_query("SELECT content3 FROM group1_pathway WHERE title = '$display_title2'");
    ?>
    <BODY>
    <div id="container">
    <div id="header">

    </div>
    <div id="breadcrumbs">

    </div>
    <div id="content">
    <p> <BR /><BR />
    <?php
    $row1=mysql_fetch_array($content1);
    $display_content1 = $row1["content1"];
    print $display_content1;
    print "<BR><BR>";
    $row2=mysql_fetch_array($content2);
    $display_content2 = $row2["content2"];
    print $display_content2;
    print "<BR><BR>";
    $row3=mysql_fetch_array($content3);
    $display_content3 = $row3["content3"];
    print $display_content3;
    print "<BR><BR>";

    ?>
    </p>
    </div>
    <div id="navbar">
    <ul>
    <li><a href="index.html">&nbsp; Home</a></li>
    <li>
    <?php
    for ($i=1; $i<=mysql_num_rows($pagenum); $i++)
    {
    echo '<a href="group1_page';
    echo $i;
    echo '.php">';

    $row2=mysql_fetch_array($titleofpage);

    $display_title = $row2["title"];
    print "&nbsp; ".$display_title;
    echo "</a></li><li>";
    }
    ?>
    </li>
    </ul>
    </div>
    </div>

    </BODY></HTML> '
    ;
    //write some lines to the file
    fputs($myFile, $data);


    // fputs($myFile, "Save this line too\n");

    //close the file
    fclose($myFile);


    // $result = mysql_query($query);
    // If the query failed, display an error.

    if(!$result) {
    // The dot seperates PHP code and plain text.
    echo "Your query failed. " . mysql_error();
    }
    else {
    // Display a success message!
    echo "Your content has been successfully uploaded to database!<br><br>";
    }
    ?>

  2. #2
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    I have made a couple of changes, you were going in and out of your $data var quotes all over the place.


    PHP Code:
    <?php 
    session_start
    ();
    if(!isset(
    $_SESSION['username']) || !isset($_SESSION['sid']) ||!isset($_SESSION['ip'])) {
    header("Location: login.php");
    exit;
    }
    include(
    "connection.php");
    $usershort $_SESSION['username'];
    $result mysql_query("SELECT groupnum FROM users WHERE username = '{$usershort}'");
    while(
    $row=mysql_fetch_array($result)) {
    $group $row['groupnum'];}

    $titleofpage $_POST['titleofpage'];

    $query "INSERT INTO group{$group}_pathway (title, content1, content2, content3) VALUES ('{$titleofpage}', 'This is some default content for content block 1', 'This is some default content for content block 2', 'This is some default content for content block 3')";

    // Perform the SQL query on the database.
    $result mysql_query($query);

    $result2 mysql_query("SELECT page FROM group{$group}_pathway WHERE title = '{$titleofpage}'");
    while(
    $row2=mysql_fetch_array($result2)) {
    $pagenum $row2['page'];}


    /*
    ** open file for writing
    */
    $sql "SELECT page FROM group{$group}_pathway WHERE title = '{$titleofpage}'";
    $qry mysql_query($sql);
    $filename "group{$group}_page{$pagenum}.php";
    if(!(
    $myFile fopen($filename"w")))
    {
    print(
    "Error: ");
    print(
    "'$filename' could not be created\n");
    exit;
    }

    $data <<<EOD
    <HTML><HEAD><link rel="stylesheet" type="text/css" href="group1_main.php"></HEAD><?php
    include("connection.php");
    \$usershort = \$_SESSION['username'];
    \$result = mysql_query("SELECT groupnum FROM users WHERE username = '{\$usershort}'");
    while(\$row=mysql_fetch_array(\$result)) {
    \$group = \$row['groupnum'];}
    \$titleofpage = mysql_query("SELECT title FROM group1_pathway");
    \$titleofpage2 = mysql_query("SELECT title FROM group1_pathway");
    \$row5=mysql_fetch_array(\$titleofpage2);
    \$display_title2 = \$row5['title'];
    \$pagenum = mysql_query("SELECT page FROM group1_pathway ORDER BY page");
    \$content1 = mysql_query("SELECT content1 FROM group1_pathway WHERE title = '{\$display_title2}'");
    \$content2 = mysql_query("SELECT content2 FROM group1_pathway WHERE title = '{\$display_title2}'");
    \$content3 = mysql_query("SELECT content3 FROM group1_pathway WHERE title = '{\$display_title2}'");
    ?>
    <BODY>
    <div id="container">
    <div id="header">

    </div>
    <div id="breadcrumbs">

    </div>
    <div id="content">
    <p> <BR /><BR />
    <?php 
    \$row1=mysql_fetch_array(\$content1);
    \$display_content1 = \$row1['content1'];
    print \$display_content1;
    print "<BR><BR>";
    \$row2=mysql_fetch_array(\$content2);
    \$display_content2 = \$row2['content2'];
    print \$display_content2;
    print "<BR><BR>";
    \$row3=mysql_fetch_array(\$content3);
    \$display_content3 = \$row3['content3'];
    print \$display_content3;
    print "<BR><BR>";

    ?>
    </p>
    </div>
    <div id="navbar">
    <ul>
    <li><a href="index.html">&nbsp; Home</a></li>
    <li>
    <?php
    for (\$i=1; \$i<=mysql_num_rows(\$pagenum); \$i++)
    {    
    echo '<a href="group1_page{\$i}.php">';

    \$row2=mysql_fetch_array(\$titleofpage);

    \$display_title = \$row2['title'];
    print "&nbsp; ".\$display_title;
    echo "</a></li><li>";
    }
    ?>
    </li> 
    </ul> 
    </div>
    </div>

    </BODY></HTML>
    EOD;
    // End Page

    //write some lines to the file
    fwrite($myFilestripslashes($data), strlen(stripslashes($data)));

    //close the file
    fclose($myFile);


    //    $result = mysql_query($query);
    // If the query failed, display an error.

    if(!$result) { 
    // The dot seperates PHP code and plain text.
    echo "Your query failed. " mysql_error();
    }
    else {
    // Display a success message!
    echo "Your content has been successfully uploaded to database!<br><br>";
    }
    ?>
    Last edited by Sheldon; 04-12-2008 at 04:41 PM.

  3. #3
    Join Date
    Mar 2008
    Posts
    13

    still isn't working

    i copied any pasted your modified code and it still isnt working.

    Parse error: syntax error, unexpected T_START_HEREDOC on line 39

    is the new error, and line 39 has the following code on it...

    <HTML><HEAD><link rel="stylesheet" type="text/css" href="group1_main.php"></HEAD><?php

    Thanks for your help!
    Last edited by xthematrix; 04-12-2008 at 04:54 PM.

  4. #4
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    try add an = sign.

    PHP Code:
    $data = <<<EOD 

  5. #5
    Join Date
    Mar 2008
    Posts
    13

    new error

    I made the correction, now im getting another error...

    Parse error: syntax error, unexpected $end on line 123

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles