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...
$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">
$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">
Bookmarks