PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Mon Apr 16, 2007 1:48 pm
i am creating a code for my admin panel that lets you edit the config.php but i dont get one thing when i am coding this
first i want to show two options, manual or automatic configuration. based on that it shows the appropriate form
heres my code so far
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
include('../include/header.php');
?>
<body>
<?php
$configfile = '../include/config.php';
$submit = $_POST['submit'];
$selectconfig = $_POST['selectconfig'];
$manual = $_POST['manualconfig'];
$auto = $_POST['autoconfig'];
$self = $_SERVER["PHP_SELF"];
//check to see if manual configuration or automatic
if (isset($selectconfig)) {
//code
} else{
echo '
<form action=' . $self . '>
<input type="radio" name="manualconfig">Manual Configuration<br>
<input type="radio" name="autoconfig">Automatic Configuration<br>
<input type="submit" name="selectconfig" value="Edit">
</form>
';
}
// if manual
if (isset($submit)){
//code
}
else {
echo '<textarea cols="45" rows="6">';
$fr = fopen($configfile, 'r');
echo $fr;
echo '</textarea>';
echo '<input type="button" name="submit">';
}
//if automatic
if (isset($submit)) {
//code
}
else{
//code
}
?>
</body><br>
<?php
include('.../include/footer.php');
?>
</html>
how would i code it so if i select manual, it shows the manual configuration form, and if i select auto, it shows the automatic configuration form?
Last edited by
ziggy3000 on Wed Apr 18, 2007 4:15 pm, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Apr 16, 2007 2:44 pm
Firstly, I would change your html form like so
Code: Select all
<input type="radio" name="config" value="manual">Manual Configuration<br>
<input type="radio" name="config" value="auto">Automatic Configuration<br>
Now, to check which one was selected, you could use a switch statement.
Code: Select all
if (isset($_POST['config']))
{
switch($_POST['config'])
{
case 'manual' :
//manual config stuff
break;
case 'auto' :
//auto config stuff
break;
default :
// invalid value
}
}
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Mon Apr 16, 2007 2:53 pm
thanks, but i have 1 question. how would you display a textarea which displays another files contents and has a submit button, so if you change the text in the textarea, and hit submit, it would write the text you had in the textarea to the file?
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Mon Apr 16, 2007 3:08 pm
it's not working...
this is my code
Code: Select all
<?php
$selectconfig = $_POST['selectconfig'];
$configfile = '.../include/config.php';
$self = $_SERVER["PHP_SELF"];
$manualconfig = $_POST['manualconfig'];
$autoconfig = $_POST['autoconfig'];
if (isset($selectconfig)) {
if (isset($_POST['config']))
{
switch($_POST['config'])
{
case 'manual' :
if (isset($manualsubmit)) {}
else {
echo '<textarea></textarea>';
}
break;
case 'auto' :
if (isset($autosubmit)) {}
else {
echo '<form action='.$self.' method="post" name="write" id="write">
<h3>Site Info</h3>
Site Title
<input name="site_title" type="text" id="site_title" >
<br>
Site Url(including http://)
<input name="site_url" type="text" id="site_url" >
<br>
<h3>Databse Information</h3>
Host
<input name="db_host" type="text" id="db_host" value="localhost" >
<br>
Database User
<input name="db_user" type="text" id="db_user" value="admin">
<br>
Database Password
<input name="db_pass" type="password" id="db_pass" >
<br>
Database Name
<input name="db_name" type="text" id="db_name" >
<br>
<h3>Administrator Information</h3>
Administrator account name
<input type="text" name="admin_user" value="Admin" id="admin_user">
<br>
Administrator Password
<input type="password" name="admin_pass">
<br>
Administrator Password Confirm
<input type="password" name="admin_cpass">
<br>
Administrator Email
<input type="text" name="admin_email" >
<h5>Security Image</h5>
<input type="text" name="code">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
';
}
break;
default :
echo 'Hacking Attempt!';
exit;
}
}
}
else {
echo '
<center>
<form action=' . $self . '>
<input type="radio" name="config" value="manual">Manual Configuration<br>
<input type="radio" name="config" value="auto">Automatic Configuration<br>
<input type="submit" name="selectconfig" value="Edit">
</form>
</center>
';
}
?>
all it does is display the select configuration method, then it resets the form. i tried selecting manual and auto, but they both reset the form then stop working... how would you fix this?
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Wed Apr 18, 2007 3:32 pm
can anyone help me?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Apr 18, 2007 4:48 pm
You are still using
Code: Select all
$manualconfig = $_POST['manualconfig'];
$autoconfig = $_POST['autoconfig'];
If you notice the form only sends a 'config' value, which it either equal to 'manual' or 'auto'...
No need for those if statements inside the switch()
For now on, set your error reporting level to E_ALL
at the top of your script, and you'll notice your using nonexistant variables.
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Wed Apr 18, 2007 4:53 pm
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i only defined those variables because inside the switch statement you gave meCode: Select all
if (isset($_POST['config']))
{
switch($_POST['config'])
{
case 'manual' :
//manual config stuff
break;
case 'auto' :
//auto config stuff
break;
default :
// invalid value
}
}
i have a form where it says //manual config stuff and // auto config stuff and those are the names of the submit buttons in those forms
i mean
Code: Select all
if (isset($_POST['config']))
{
switch($_POST['config'])
{
case 'manual' :
echo <<< form
<form>
<textarea>
</textarea>
<input type="submit" name="manualconfig">
</form>
break;
case 'auto' :
<form>
<input type="text">
<input type="text">
<input type="submit" name="autoconfig">
</form>
break;
default :
// invalid value
}
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Wed Apr 18, 2007 5:32 pm
nevermind, i got it to work
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Thu Apr 19, 2007 3:25 pm
i need help creating a textarea which displays another's files contents(i don't know why but it's not working for me...)
here's my code
Code: Select all
$self = $_POST["PHP_SELF"];
$fh23 = fopen($file, 'r');
echo "<form action=\"$self\" method=\"post\"><textarea value=\"$fh23\" name=\"change\"></textarea><input type=\"submit\" name=\"write\" value=\"Write\">";
when i parse this my html code is
Code: Select all
<form action="/index.php" method="post"><textarea value="Resource id #3" name="change"></textarea><input type="submit" name="write" value="Write">
but i don't know why it says "Resource id #3" the script i am viewing has the following contents
help please...
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 19, 2007 3:50 pm
Seriously dude, you need to start reading the manual before posting.
fopen() returns a resource id, which fread() will use to read the file.
You probably want file_get_contents() anyways.
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Thu Apr 19, 2007 3:52 pm
i got this off of
here ... i thought this site had correct info...
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 19, 2007 3:54 pm
It does.. I take it you only read the first couple sentences.
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Thu Apr 19, 2007 3:56 pm
actually, i just looked for the code i needed... (guess i should put the manual as my homepage)
guitarlvr
Forum Contributor
Posts: 245 Joined: Wed Mar 21, 2007 10:35 pm
Post
by guitarlvr » Thu Apr 19, 2007 3:58 pm
fread() was used in the lower part of the article you linked to.
Wayne
ziggy3000
Forum Contributor
Posts: 205 Joined: Fri Mar 23, 2007 3:04 pm
Post
by ziggy3000 » Thu Apr 19, 2007 4:00 pm
guess i should have looked at the whole page, instead at the top