Page 1 of 1

adding a PHP settings page

Posted: Mon Jan 17, 2011 3:07 pm
by bigjoe11a
I have a php script named settings.php. In the file I have 3 settings that I need to read from a mysql database, and then display the on, off status of each setting. That part I know how to do.

The problem I'm having is getting it to update the database when I change the value from a drop down box and click the submit button.

The idea is too have 3 settings that I can turn on, or off from a mysql database. Below is my code. Can some one Please HELP

Code: Select all

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

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

error_reporting(-1);
ini_set("display_errors", -1);

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

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

$temp1 = $_POST['temp1'];
$temp2 = $_POST['temp2'];
$temp3 = $_POST['temp3'];
	
$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">';

$t = 1;

while($row = $db->fetchArray($result))
  {   
	  echo '<tr>';
	  echo '<td>'.$row['setname'].'</td><td><select size="1" name=temp'.$t.'>';
    
	  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>";
	  $t = $t = 1;
  }
  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>
I been programing in PHP for a little more then 4 years. I wanted to learn how to use classes and custom options.
PLEASE HELP......

Joe

Re: adding a PHP settings page

Posted: Mon Jan 17, 2011 10:01 pm
by bigjoe11a
Well I guess registering on this forums section was a waste of my time.

Re: adding a PHP settings page

Posted: Tue Jan 18, 2011 2:11 am
by Peter Kelly
Joe we need more information like errors? what its doing what its not doing? we can only help if we know the problem. One thing though can I ask why you have done.

Code: Select all

$t = $t = 1;
as I can't see why that has been done as your just setting it twice :S