Ninjakreborn Posted October 7, 2006 Share Posted October 7, 2006 The code does everything it's suppose to but one thing. It takes the template page, and put's it int eh right directory as index.php, but it's blank it's not 1. Copying the info from the specified template page, 2. Updating the content??[code]<?phpsession_start();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Thank You</title></head><body><?phpif ($_SESSION['controller'] == true) {mysql_connect("localhost", "#####", "#####");mysql_select_db("hasbadse_hbservice");// create user account.$errorhandler = "";$insert = "INSERT INTO userinfo SET username = '$_SESSION[username]', password = '$_SESSION[password]', email = '$_SESSION[email]', subdomainname = '$_SESSION[subdomain]';";mysql_query($insert);$select = "SELECT * FROM userinfo WHERE username = '$_SESSION[username]';";$query = mysql_query($select);if ($row = mysql_fetch_array($query)) { // retrieve userid with user account. $id = $row['id']; } // end getting userid.$header = $_SESSION['header'];$text = $_SESSION['text'];$insertcms = "INSERT INTO usercms (header, text, userid) VALUES ('$header', '$text', '$id');";if (!mysql_query($insertcms)) {$errorhandler .= "There was a problem inserting the Content Management Information.<br />";$errorhandler .= "Please contact support about this problem.<br />";}// VERY IMPORTANT, everything below is used for directory creation.$var = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord($0).";"', $_SESSION['subdomain']);$dir = "userpages/$var";mkdir("$dir", 0700);if (!mkdir) {$errorhandler .= "unable to create the directory. Please contact support or try again.<br />";}$infile = fopen($_SESSION['template'], "r"); // as readonlywhile (!feof($infile)) { $buffer = fread($infile, filesize($_SESSION['template'])); }fclose($infile);$buffer = str_replace("$id", $id, $buffer);// here I can do all my changes to the buffer variable(which contains the file information)$outfile = fopen("userpages/{$var}/index.php", "w"); // open writeablefwrite($outfile, $buffer);fclose ($outfile);// VERY IMPORTANT, everything above here is used for directory creation.$insertdn = "INSERT INTO subdomain (path, subdomainname, userid) VALUES ('$dir', '$_SESSION[subdomain]', '$id');";if (!mysql_query($insertdn)) {$errorhandler .= "There was a problem, please contact support immediately.<br />";}// start check for error handlerif ($errorhandler != "") {echo "<span style=\"color:red;\">";echo $errorhandler;echo "</span>";}if ($errorhandler == "") {?><h4>Thank You</h4><p>Thank you for your purchase, you can go over to the administration page, and login there.</p><a href="/useradmin.php" title="User Admin">User Admin</a><?php }}else {echo "You have to go through the entire signup process, before coming to this page, in order <br />";echo "for your account to be able to be created.<br />";}?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 7, 2006 Share Posted October 7, 2006 try not closeing the infile until after you have written to the the outfile.Good Luck,Tom Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 7, 2006 Author Share Posted October 7, 2006 I moved closing it down right above closing the other, and it still didn't work? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 7, 2006 Share Posted October 7, 2006 try using [code=php:0]file_get_contents[/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 7, 2006 Author Share Posted October 7, 2006 Where should I use that at, I mean what should I replace with that? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2006 Share Posted October 7, 2006 Here's a cluehttp://www.php.net/fopenhttp://www.php.net/feofhttp://www.php.net/freadhttp://www.php.net/fcloseNow look athttp://www.php.net/file_get_contents Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 7, 2006 Author Share Posted October 7, 2006 Thanks I will try look at those, study them awhile, look through google some, try the code again with different variations, adn if I keep running into a brick wall I will ask again, thanks for the help. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 8, 2006 Author Share Posted October 8, 2006 Everything on the other pages are the same, I redid the stuff on the thankyou page, and there I used a function I found on php.netNow I have a question.Here is my new altered code.[code]<?phpsession_start();function read_file($file){ if(!function_exists("file_get_contents"))return file_get_contents($file); $ifile = fopen($file,"r"); $contents = false; if($ifile) while (!feof($ifile)) $contents .= fgets($ifile); fclose($ifile); return $contents;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Thank You</title></head><body><?phpif ($_SESSION['controller'] == true) {mysql_connect("localhost", "#####", "######");mysql_select_db("hasbadse_hbservice");// create user account.$errorhandler = "";$insert = "INSERT INTO userinfo SET username = '$_SESSION[username]', password = '$_SESSION[password]', email = '$_SESSION[email]', subdomainname = '$_SESSION[subdomain]';";mysql_query($insert);$select = "SELECT * FROM userinfo WHERE username = '$_SESSION[username]';";$query = mysql_query($select);if ($row = mysql_fetch_array($query)) { // retrieve userid with user account. $id = $row['id']; } // end getting userid.$header = $_SESSION['header'];$text = $_SESSION['text'];$insertcms = "INSERT INTO usercms (header, text, userid) VALUES ('$header', '$text', '$id');";if (!mysql_query($insertcms)) {$errorhandler .= "There was a problem inserting the Content Management Information.<br />";$errorhandler .= "Please contact support about this problem.<br />";}// VERY IMPORTANT, everything below is used for directory creation.$var = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord($0).";"', $_SESSION['subdomain']);$dir = "userpages/$var";mkdir("$dir", 0700);if (!mkdir) {$errorhandler .= "unable to create the directory. Please contact support or try again.<br />";}$buffer = read_file($_SESSION['template']);$buffer = str_replace("$id", $id, $buffer);// here I can do all my changes to the buffer variable(which contains the file information)$outfile = fopen("userpages/{$var}/index.php", "w"); // open writeablefwrite($outfile, $buffer);fclose ($outfile);// VERY IMPORTANT, everything above here is used for directory creation.$insertdn = "INSERT INTO subdomain (path, subdomainname, userid) VALUES ('$dir', '$_SESSION[subdomain]', '$id');";if (!mysql_query($insertdn)) {$errorhandler .= "There was a problem, please contact support immediately.<br />";}// start check for error handlerif ($errorhandler != "") {echo "<span style=\"color:red;\">";echo $errorhandler;echo "</span>";}if ($errorhandler == "") {?><h4>Thank You</h4><p>Thank you for your purchase, you can go over to the administration page, and login there.</p><a href="/useradmin.php" title="User Admin">User Admin</a><?php }}else {echo "You have to go through the entire signup process, before coming to this page, in order <br />";echo "for your account to be able to be created.<br />";}?></body></html>[/code]Ok everything here now works but one thing, at first a lot was wrong with it, but now it's moving it to the directory, properly copying the file contents as needed. Everything is so far working, but the string replace isn't doing what it's suppose it. It's suppose to find the occurence of $idand change $id to the number of the user id, so it can find those entries in the database. Quote Link to comment Share on other sites More sharing options...
alpine Posted October 8, 2006 Share Posted October 8, 2006 If you are meaning this one -> $buffer = str_replace("$id", $id, $buffer); it is replacing $id with $id and that's the exact same value.So you have to rename one of them to something different. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 8, 2006 Author Share Posted October 8, 2006 It didn't work, I changed the test within the template pages to hold instead of id, and I am trying to get it to take the value of id, and insert it where hold is on hte template page, but it's not working.I am also sure my id variable has the right contents, I don't get why it's not working, any advice. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 8, 2006 Author Share Posted October 8, 2006 nevermind I just got it, it had something else wrong, I was pointing the query to look for the userid, instead of the id, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.