Jump to content


Photo

not updating text


  • Please log in to reply
10 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 07 October 2006 - 04:40 AM

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??
<?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>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 October 2006 - 04:59 AM

try not closeing the infile until after you have written to the the outfile.


Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 07 October 2006 - 05:04 AM

I moved closing it down right above closing the other, and it still didn't work?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 October 2006 - 05:20 AM

try using
file_get_contents

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 07 October 2006 - 05:25 PM

Where should I use that at, I mean what should I replace with that?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 07 October 2006 - 08:21 PM

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


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 07 October 2006 - 10:44 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 08 October 2006 - 04:15 AM

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.

<?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>

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 08 October 2006 - 04:34 AM

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.

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 08 October 2006 - 04:40 AM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 08 October 2006 - 04:47 AM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users