bigjoe11a Posted January 16, 2011 Share Posted January 16, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/ Share on other sites More sharing options...
joel24 Posted January 16, 2011 Share Posted January 16, 2011 have you tested your code to see if it works? Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160421 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 have you tested your code to see if it works? Yes I have and no it doesn't... Like I said I never done any thing like this before. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160425 Share on other sites More sharing options...
joel24 Posted January 16, 2011 Share Posted January 16, 2011 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'])) { Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160428 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160439 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 Maybe I should find another forums section, since this one isn't panning out Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160465 Share on other sites More sharing options...
joel24 Posted January 17, 2011 Share Posted January 17, 2011 put this line at the top of the PHP and post what it echoes print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160477 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160483 Share on other sites More sharing options...
atrum Posted January 17, 2011 Share Posted January 17, 2011 I don't think print_r will print anything to the screen unless you echo it. so add this instead (with some formatting so its easier on the eyes) echo "<pre>"; echo print_r($_POST); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160521 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 print_r() doesn't need to be echoed. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160524 Share on other sites More sharing options...
atrum Posted January 17, 2011 Share Posted January 17, 2011 print_r() doesn't need to be echoed. Ok, I have never tried with out Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160525 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 Thanks guys, how ever that doesn't help me to get this to work. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160528 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 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."''"); Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160531 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160667 Share on other sites More sharing options...
KevinM1 Posted January 17, 2011 Share Posted January 17, 2011 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(); ). Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160683 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160696 Share on other sites More sharing options...
KevinM1 Posted January 17, 2011 Share Posted January 17, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160726 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160804 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 This editor is jumping all over the place. I can't even be sure of what I'm typing, Admin need to check on that. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160808 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160809 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160825 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2011 Share Posted January 17, 2011 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? 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? Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160830 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 1) No I don't expect any one to do any thing 2) This forum section is a joke 3) This forum section is being added to my blacklist 4) Just delete or remove my account. Since no one is wanting to even try and help Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160843 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1160845 Share on other sites More sharing options...
KevinM1 Posted January 18, 2011 Share Posted January 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224644-php-settings-pages/#findComment-1161303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.