Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

not updating text

Recommended Posts

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]<?php
session_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>
<?php
if ($_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 readonly
while (!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 writeable
fwrite($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 handler
if ($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]

Share this post


Link to post
Share on other sites
try not closeing the infile until after you have written to the the outfile.


Good Luck,
Tom

Share this post


Link to post
Share on other sites
Here's a clue

http://www.php.net/fopen
http://www.php.net/feof
http://www.php.net/fread
http://www.php.net/fclose

Now look at

http://www.php.net/file_get_contents

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.net
Now I have a question.

Here is my new altered code.

[code]<?php
session_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>
<?php
if ($_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 writeable
fwrite($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 handler
if ($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 $id
and change $id to the number of the user id, so it can find those entries in the database.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.