Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-17-2005, 04:48 PM Is This Possable??!!
SpottyDog's Avatar
Skilled Talker

Posts: 82
Trades: 0
Hey guys,

I have an idea and i just want to know if its possable.

I want to use the copy() function and use a variable from a form to generate a page. named by whatever the user put in the text field.
Now thats the easy bit, i can do that.

The thing is i want to change the content in the new page. In the template it will be querying and SQL database.

Now i want to change what field it queries, depending on the name of the page.

So if the user set the page name to be TEST then the sql query will look for a field called TEST.

Is this possable??

Thanks
SpottyDog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-17-2005, 05:28 PM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
i don't think i get the question.

you get TEST from the form with $_POST['blabla'] (which is "TEST"),

now that you have it, you create the page ... well ... can't you use the same value for the query?
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-17-2005, 06:09 PM
SpottyDog's Avatar
Skilled Talker

Posts: 82
Trades: 0
yes, i use that to make the new page and its all sorted. But what i want is for it to change the actual text in the file so it is permanantly querying the same place when it is loaded.

So i want to copy a file but change a little bit of the content of the file everytime its copied
SpottyDog is offline
Reply With Quote
View Public Profile
 
Old 05-17-2005, 06:15 PM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
you create the file you are copying (like a template) with an identifier where you need the "TEST" to come, and when the form is evaluated, you parse the file and then write it ... don't know if it's the easiest way to do it ...

another easier way would be for you to only have something like
PHP Code:
<?php
$page 
"TEST";
include(
'a file i\'ll tell you about now');
?>
instead of copying the file you write itr directly since it's only 4 lines, and the file you are including there contains the variable $page exactly where your sql query is ...
that way you save some space and keep your main code in one single place in case of any later problems
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.

Last edited by OmuCuSucu; 05-17-2005 at 06:17 PM..
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-17-2005, 06:41 PM
SpottyDog's Avatar
Skilled Talker

Posts: 82
Trades: 0
Yes that is a very good idea

Only problem is that i cant write the file manually. I need it to be automated for a client so he can easily add pages.
SpottyDog is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 01:35 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
by write i don't mean it that way... i mean instead of using copy() you should use fopen and open it directly for editing and your php script should "write" it
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 07:36 AM
SpottyDog's Avatar
Skilled Talker

Posts: 82
Trades: 0
Can you help me come up with some code please?

Last edited by SpottyDog; 05-18-2005 at 08:16 AM..
SpottyDog is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 08:09 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
example taken from php's documentation:

PHP Code:
<?php
$filename 
'test.txt';
$somecontent "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    
// In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence 
    // that's where $somecontent will go when we fwrite() it.
    
if (!$handle fopen($filename'a')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
        echo 
"Cannot write to file ($filename)";
        exit;
    }
    
    echo 
"Success, wrote ($somecontent) to file ($filename)";
    
    
fclose($handle);
                    
} else {
    echo 
"The file $filename is not writable";
}
?>
i couldn't tell you more than THAT it seems as expressive as it can gat

good luck with it
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 08:14 AM
SpottyDog's Avatar
Skilled Talker

Posts: 82
Trades: 0
Ok, i have looked in fopen etc and i have come up with

PHP Code:
<?php

//File Name From Form

$file=$_POST["filename"];
if (
$file == "")
  {

// What To Show If No Text Was Entered

  
echo "<p>You Didn't Enter A Search.....</p>";
  }

//Open the file, if it doesn't exist, create it

$fp fopen("$file.php","w");
$str "<?php $page = "$file"; include('template.php'); ?>";
fwrite ($fp,$str "\r\n");
fclose($fp);

?>
I get an error on line 17 which is
PHP Code:
$str = "<?php $page "$file"; include('template.php'); ?>";
How do i make it work?

Last edited by SpottyDog; 05-18-2005 at 08:19 AM..
SpottyDog is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 08:21 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
i've made some changes:

PHP Code:
<?php

//File Name From Form

$file=$_POST["filename"];
if ((
$file == "") || (is_space($file)))
  {

// What To Show If No Text Was Entered

  
echo "<p>You Didn't Enter A Search.....</p>\n";
  }

//Open the file, if it doesn't exist, create it

$fp fopen("$file.php","w");
$str "<?php $page = "$file"; include('template.php'); ?>"// <--- check to see if $page is not interpreted - which would result in a NULL value being written.
fwrite ($fp,$str "\r\n");
fclose($fp);

?>
i'd say $page should go like this:
PHP Code:
$str = "<?php '$page' = \"$file\"; include('template.php'); ?>"
also where you check if the file name is specified ... check also if it's not all spaces. (i think is_space as i showed you is ok.
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.

Last edited by OmuCuSucu; 05-18-2005 at 08:24 AM..
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Is This Possable??!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.29336 seconds with 12 queries