Jump to content

PHP Settings Pages


bigjoe11a

Recommended Posts

what I'm trying to do is to setup a page called settings.php that the admin runs to order to turn option in the web site on or off. I don't know how to do this since I never done this before. My code is below.

 

<link href="mainframe.css" rel="stylesheet" type="text/css">

<?php
require_once '../config.php';

$db = new DbConnector();
$db->DbConnector();


if(isset($_GET['submit'])) {

$db->query('UPDATE '.SETTING_TABLE.' SET option='.$_POST['banner'].' WHERE setname=''');

  echo 'Process complete';	
}

$result = $db->query('SELECT * FROM '.SETTINGS_TABLE);

echo '<table border="1">';
echo '<tr>';

echo '<form action="settings.php" methed="post">';

while($row = $db->fetchArray($result))
  {
   
  echo '<tr>';
  echo '<td>'.$row['setname'].'</td><td><select size="1" name="'.$row['setname']'">';
  echo '<option value="on">on</option>';
  echo '<option value="off">off</option>';
  echo '</td>';  
  echo "</tr>";
  }
  echo '<td><input type="submit" value="Submit" name="submit">';
  echo '</td>';

echo "</tr>";
echo "</form>";
echo "</table>";

/*
*/

?>

<h2>Settings</h2>

<a href = "admin.php">Admin Panel</a>


 

Link to comment
Share on other sites

for starters you're posting the form variables and trying to retrieve them with $_GET

if(isset($_GET['submit'])) {
//this line should be
if(isset($_POST['Submit'])) {

 

Ok, that's one thing fixed. I hope. can you help me with the rest of it.

 

Link to comment
Share on other sites

I add that in the code. I psted my new code below, and it passes nothing, Nothing at all

 

<link href="mainframe.css" rel="stylesheet" type="text/css">

<?php
require_once '../config.php';

$db = new DbConnector();
$db->DbConnector();

if(isset($_POST['Submit'])) {

print_r($_POST);
exit;

$temp2 = $_POST['name'];

$db->query("'UPDATE '".SETTINGS_TABLE."' SET option='".$temp1."', option='".$temp2."', option='".$temp3."''");	
  echo 'Process complete';	
}

$result = $db->query('SELECT * FROM '.SETTINGS_TABLE);

echo '<table border="2">';
echo '<tr>';

echo '<form action="settings.php" methed="post">';

while($row = $db->fetchArray($result))
  {
   
  echo '<tr>';
  echo '<td>'.$row['setname'].'</td><td><select size="1" name="'.$row['setname'].'">';
  
  if($row['option'] == 'on') {  
  echo '<option value="on" selected>on</option>';
  } else {
 echo '<option value="on">on</option>'; 
  }   
  if($row['option'] == 'off') {
  echo '<option value="off" selected>off</option>';
  }  else {
 echo '<option value="off">off</option>'; 
  }
  echo '</select>';
  echo '</td>';  
  echo "</tr>";
  }
  echo '<td><input type="submit" value="Submit" name="Submit">';
  echo '</td>';

echo "</tr>";
echo "</form>";
echo "</table>";

/*
*/

?>

<h2>Settings</h2>

<a href = "admin.php">Admin Panel</a>


 

Link to comment
Share on other sites

1) You should be developing with error_reporting set to -1 and display_errors set to On

2) $temp1 and $temp3 are undefined.

3) This query string has syntax errors, attempts to set the same field to a different value 3 times and probably needs a WHERE clause:

$db->query("'UPDATE '".SETTINGS_TABLE."' SET option='".$temp1."', option='".$temp2."', option='".$temp3."''");

Link to comment
Share on other sites

1) You should be developing with error_reporting set to -1 and display_errors set to On

2) $temp1 and $temp3 are undefined.

3) This query string has syntax errors, attempts to set the same field to a different value 3 times and probably needs a WHERE clause:

$db->query("'UPDATE '".SETTINGS_TABLE."' SET option='".$temp1."', option='".$temp2."', option='".$temp3."''");

 

1) I don't know how to do that

2) Yes I know that. That's why I'm asking for help.

3) I know, that. The vars come form the form it self. Just above that line I added 3 $temp? = $_POST['name'];

 

 

Link to comment
Share on other sites

1) You should be developing with error_reporting set to -1 and display_errors set to On

2) $temp1 and $temp3 are undefined.

3) This query string has syntax errors, attempts to set the same field to a different value 3 times and probably needs a WHERE clause:

$db->query("'UPDATE '".SETTINGS_TABLE."' SET option='".$temp1."', option='".$temp2."', option='".$temp3."''");

 

1) I don't know how to do that

 

At the top of your script, put:

 

<?php
error_reporting(-1);
ini_set("display_errors", 1);
?>

 

Also, Google and the PHP manual are your friends.  If you don't know something, always search there.

 

2) Yes I know that. That's why I'm asking for help.

3) I know, that. The vars come form the form it self. Just above that line I added 3 $temp? = $_POST['name'];

 

You seem to be very confused about what your form contains and how to pass that info along to the db.  You should probably show us the form itself so we can see exactly what your db query should be.

 

Also, since you're using a DbConnector object, you most likely don't have to write:

 

$db->DbConnector();

 

An object's constructor is called automatically when one asks for a new object (e.g. $db = new DbConnector(); ).

Link to comment
Share on other sites

1) You should be developing with error_reporting set to -1 and display_errors set to On

2) $temp1 and $temp3 are undefined.

3) This query string has syntax errors, attempts to set the same field to a different value 3 times and probably needs a WHERE clause:

$db->query("'UPDATE '".SETTINGS_TABLE."' SET option='".$temp1."', option='".$temp2."', option='".$temp3."''");

 

1) I don't know how to do that

 

At the top of your script, put:

 

<?php
error_reporting(-1);
ini_set("display_errors", 1);
?>

 

Also, Google and the PHP manual are your friends.  If you don't know something, always search there.

 

2) Yes I know that. That's why I'm asking for help.

3) I know, that. The vars come form the form it self. Just above that line I added 3 $temp? = $_POST['name'];

 

You seem to be very confused about what your form contains and how to pass that info along to the db.  You should probably show us the form itself so we can see exactly what your db query should be.

 

Also, since you're using a DbConnector object, you most likely don't have to write:

 

$db->DbConnector();

 

An object's constructor is called automatically when one asks for a new object (e.g. $db = new DbConnector(); ).

 

The form your asking for is all ready included with that PHP script above.

I added the form to the PHP and then just have the script call the same script.

 

and I'll try and add that error option to the top of my script and see what happens. It's like I said I never done this in PHP before and it all new to me. I been coding PHP for 4 years and I think it's about time I learn how to do more advance PHP.

 

Link to comment
Share on other sites

I tried cleaning it up a bit for you.  Not tested, obviously.  Be sure to read my comments.

 

<?php
error_reporting(-1);
ini_set("display_errors", 1);

require_once '../config.php';

$db = new DbConnector();

if (isset($_POST['submit']))
{
	$db->query("UPDATE " . SETTING_TABLE . "SET option = {$_POST['banner']} WHERE setname = ''"); // <-- Are you sure your WHERE clause is correct?  Also, where does banner come from?
	echo "Process complete.";
}

$settings = $db->query("SELECT * FROM " . SETTING_TABLE);

while($row = $db->fetchArray($settings))
{
	$selectOption = '<td>' . $row['setname'] . '</td><td><select size="1" name="' . $row['setname'] . '">';

	if ($row['option'] == 'on')
	{
		$selectOption .= '<option value="on" selected>on</option><option value="off">off</option></select></td>';
	}
	else
	{
		$selectOption .= '<option value="on">on</option><option value="off" selected>off</option></select></td>';
	}
}
?>

<!doctype html>
<html lang="en-us">
<head>
	<title>Form</title>
	<link href="mainframe.css" rel="stylesheet" type="text/css">
</head>

<body>
<!-- You should really make sure your table is formatted properly -->
	<table border="1">
		<tr>
			<form action="settings.php" methed="post">
				<tr>
					<?php echo $selectOption; ?>
				</tr>
				<tr>
					<td><input type="submit" value="Submit" name="submit" /></td>
				</tr>
			</form>
		</tr>
	</table>

	<h2>Settings</h2>
	<a href = "admin.php">Admin Panel</a>
</body>

</html>

Link to comment
Share on other sites

Thanks, Night, How ever untested code never works and well your doesn't work. I don't see any since in making some thing that's unsetted and you should all ways test your code before posting it. I was getting all kinds of errors. I never done any thing like this before so I have no idea on how to  fix your code or my code.

 

See the idea is that I have 3 settings in a mysql database. The idea is too turn thoses 3 settings on or off on the setting.php page, With not having to edit the page it self.

 

if($settings['banner'] == 'off') {

echo 'This are is closed';

exit;

}

 

if($settings['banner'] == 'on') {

echo '<a href="banner.php">Banner</a>';

}

 

 

any way get the idea.

 

and one more question, ehy does this edit jump all over the place. I can't even be sure of what I'm typing

 

Joe

 

 

Link to comment
Share on other sites

We aren't here to provide people with fully tested, guaranteed-to-be-working code on demand. If you want that, I'd suggest you pay someone to write it for you.

 

Right, and that's a joke. The idea of having a forums section is to help people. Not charge them for what they may or may not need. If that's the case, Your joke is in poor taste.

 

 

 

Link to comment
Share on other sites

Thanks, Night, How ever untested code never works and well your doesn't work. I don't see any since in making some thing that's unsetted and you should all ways test your code before posting it. I was getting all kinds of errors. I never done any thing like this before so I have no idea on how to  fix your code or my code.

 

Joe

 

:wtf:Your not actualy serious are you? :wtf:

Right, and that's a joke.

I don't think there is an adjective in any langauge that cover this level of stupidity....You can't seriously think that you can just make a couple half assed posts and people will fall over each other to write YOUR code for you?

Link to comment
Share on other sites

We aren't here to provide people with fully tested, guaranteed-to-be-working code on demand. If you want that, I'd suggest you pay someone to write it for you.

Right, and that's a joke. The idea of having a forums section is to help people. Not charge them for what they may or may not need. If that's the case, Your joke is in poor taste.

 

 

 

No, it isn't a joke at all. Coming in here demanding that people replicate your database and development environment, take your shoddily written code and poor description of what you want, then write new code for you and test it to be certain it works before posting it free of charge is what the real joke is.

 

Now, if you have a specific piece of code, with which you have specific problem, post a succinct, concise, accurate description of the problem, along with the relevant code. That shouldn't be any problem at all for someone who's been writing php code for for years, such as yourself, correct?

Link to comment
Share on other sites

The code wasn't tested because I don't have access to your database, and wasn't entirely sure of how your db was structured.  How can I test db functionality in that manner, short of going through a lot of hoops that are outside the scope of something like this?  Further, you keep changing the details - first, you have one option that can be changed, now you have three?  Your form doesn't even address your 'banner' setting, let alone the second of the three options you refer to.  Did you even read the comments I wrote in the code?  Probably not.

 

In my years here, I've learned that the quality of answer received is directly proportional to the quality of the question asked.  You're going to have to learn how to communicate your problem(s) much more effectively.  How is your settings table structured?  What do you mean by "it's not working?"  Do you have a test page we can access?  Have you tried basic debugging techniques, like echoing out the values of the $_POST array?  Is the code you provided your actual code or a rough example/sketch of what you're trying to do?

 

It doesn't matter where you go for help, everyone will say the same thing: be crystal clear about what you want.

 

Personally, I could care less if you decide to stick around here.  Your attitude sucks, and, frankly, this community is better off without people like that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.