Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Using a Form to write variables to a php page

Posted by crazyjake (crazyjake), 9 March 2004
Hi,

I have a php file called: 1.php which contains:

<?

include("config.php");

print "the title are <B>$page_title</B> and my name is <B>$my_name</B><BR>";
echo "my favorite quote <B>$my_quote</B> i dont forget my last name are <B>$my_lastname</B>";
   

?>


This will include the the config.php page and then the variables such as $page_title will be displayed on the page.

The config.php file contains:

<?php

$page_title = "this is the page title";

$my_quote = "this is my quote";

$my_name = "this is my name";

$my_lastname = "this is my last name";

 
?>

So this is a list of variables that have some strings assigned to them.

Now all i would like help with is a form that could read the variables and actually display them in textboxes, then the user could see what was originally in there and the user can easily edit them. Once the textboxes have been changed i would like a submit button that would submit the information in each textbox field back into the config.php page.

Basically want a page that will allow me to change the variables in the config.php page.
Please explain everything if you can as it will also help me learn.

thanks very much for yout time and help guys.

Jason


Posted by admin (Graham Ellis), 10 March 2004
Hi, Jake ... welcome to the board.  I'm out of the office this week and dialling in "International" so this is just a brief reply ... I think what you're looking for is something like "sticky boxes" - a regular PHP topic.
I wrote an article on this is the Autumn, 2003 issue of our "Of Course" magazine, including a full source code listing. It's available for download from http://www.wellho.net/downloads

Posted by crazyjake (crazyjake), 10 March 2004
Hi,

I am actually a PHP n00b only started 3days back.

I know hardly anything apart from what is going on in my script.
I can easily follow mine.

But the one in that PDF magazine/book was a bit weird its kinda an email form.

I have no idea please help, I have explained as much as I can!

Cheers Guys, thx for trying to help Graham but im a n00b hehe

Posted by Chris_Isaac (Chris Isaac), 11 March 2004
Hi

The form below should do what you want, but by no means is it elegant, and I'm sure theres a better way of doing it, also it doesn't look at any security with regard to possible millicious/accidental data entered into the form, but it works  

Code:
<?php

// include the varibles in this file

include("myvaribles.php4");

?>


<form>
<input type="text" name="page_title" value="<?php echo"$page_title" ?>">
<input type="text" name="my_quote" value="<?php echo"$my_quote" ?>">
<input type="text" name="my_name" value="<?php echo"$my_name" ?>">
<input type="text" name="my_lastname" value="<?php echo"$my_lastname" ?>">

<input type="hidden" name="moveon" value=2>
<input type="submit" name="Submit">
</form>

<?php

//  GET the varibles from the form above

$moveon=$_GET[moveon];
$page_title=$_GET["page_title"];
$my_quote=$_GET["my_quote"];
$my_name=$_GET["my_name"];
$my_lastname=$_GET["my_lastname"];



//Following code overwrites myvaribles.php4 with the new data

if($moveon==2) {
           $fh=fopen("c:\Program Files\Apache Group\Apache2\htdocs\myvaribles.php4","w");
           fwrite($fh,"<?php\n");
           fwrite($fh,"\$page_title = \"$page_title\";\n");
           fwrite($fh,"\$my_quote = \"$my_quote\";\n");
           fwrite($fh,"\$my_name = \"$my_name\";\n");
           fwrite($fh,"\$my_lastname = \"$my_lastname\";\n");
           fwrite($fh,"?>");
           fclose($fh);
           print "Values changed in myvaribles.php4<br>";
           print "\$page_title = $page_title, \$my_quote = $my_quote, \$my_name = $my_name, \$my_lastname = $my_lastname";
     }
?>




Hope this helps.

Posted by crazyjake (crazyjake), 11 March 2004
Thanks loads!
Looks really good!
I am thinking of using it as a control panel for my site to easily edit content.

Thats the script for each page and I have CHMODED the correct file, but once i submit to the file once, i try to submit again and I need it to update over the old variables is this possible?


Quote:
<html>
<head>
</head>

<body>

<?php

// include the varibles in this file

include("myvariables.php");

?>


<form>
<input type="text" name="page_title" value="<?php echo"$page_title" ?>">
<input type="text" name="my_quote" value="<?php echo"$my_quote" ?>">
<input type="text" name="my_name" value="<?php echo"$my_name" ?>">
<input type="text" name="my_lastname" value="<?php echo"$my_lastname" ?>">

<input type="hidden" name="moveon" value=2>
<input type="submit" name="Submit">
</form>  

</body>
</html>


Quote:
<?php

//  GET the variables from the form above

$moveon=$_GET[moveon];
$page_title=$_GET["page_title"];
$my_quote=$_GET["my_quote"];
$my_name=$_GET["my_name"];
$my_lastname=$_GET["my_lastname"];



//Following code overwrites myvariables.php with the new data

if($moveon==2) {
 $fh=fopen("myvariables.php","w");
 fwrite($fh,"<?php\n");
 fwrite($fh,"\$page_title = \"$page_title\";\n");
 fwrite($fh,"\$my_quote = \"$my_quote\";\n");
 fwrite($fh,"\$my_name = \"$my_name\";\n");
 fwrite($fh,"\$my_lastname = \"$my_lastname\";\n");
 fwrite($fh,"?>");
 fclose($fh);
 print "Values changed in myvariables.php<br>";
 print "\$page_title = $page_title, \$my_quote = $my_quote, \$my_name = $my_name, \$my_lastname = $my_lastname";
}
?>



Quote:
<html>
<head>
</head>

<body>
Says my variables!
<?php

// include the varibles in this file

include("myvariables.php");

?>
<BR>
<?php echo"$page_title" ?>
<br>
<?php echo"$my_quote" ?>
<BR>
<?php echo"$my_name" ?>
<BR>
<?php echo"$my_lastname" ?>
<BR>
</body>
</html>


Posted by Chris_Isaac (Chris Isaac), 11 March 2004
I'm not sure I completely understand what your trying to do, are you saying you needed to update several different files with data from the form?  or do you wish to just keep updating (in this case) the file called myvaribles.php4

If its the latter, just reenter the new data if your still on the page, or reload it, it will bring in the latest varibles for you to overwrite as before.




Posted by crazyjake (crazyjake), 11 March 2004
yeh cheers m8!

I was overriding a file that the form needed, solved it now cheers!

works well good



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho