HAving hard time with php(MySQL) and htmt _POST function

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

Post Reply
VicToMeyeZR
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 9:02 pm

HAving hard time with php(MySQL) and htmt _POST function

Post by VicToMeyeZR »

Hi y'all. I know I am new to the forums.. I would really appreciate some help. I am not real strong in php... yet. But learning.

I have some stuff that I am trying to get to work, and I know my code is so close, but seems to be missing something. What I am doing is storing a module admin configuration into a MySQL database. The html form when loaded pulls the variables out of the Table and puts them into the Form fields, so you can change what you want and click submit and it will update that table with the new fields. My only problem and all of it works except the check box. It is supposed to store a 1 or 0 based off of the check box. SO my problem.

1. The form will not update the table with the new post variable 1 or 0.

2. The form will not load the existing variable and make the check box checked or uncheck depending on if the table already has a 1 or 0.

I hope that was clear enough. Here is the code.

This is the post form

Code: Select all

echo "<h3>Settings</h3>";
        echo $message != "" ? "<p><b>$message</b></p>" : "" ;
        echo "<form action='$modulelink' method='post'>";
        echo "<table><tr><td>Version: </td><td>".$settings['Version']."</td></tr>";
        echo "<tr><td>Enabled:</td><td><input type='checkbox' name='Enabled' value='".($settings['Enabled'] == '1' ? 'CHECKED' : '')."'/></td></tr>";
        echo "<tr><td>License Key:</td><td><input size='20' type='text' name='LicenseKey' value='".$settings['LicenseKey']."'/></td></tr>";
        echo "<tr><td>System Name:</td><td><input size='20' type='text' name='SystemName' value='".$settings['SystemName']."'/></td></tr>";
        echo "<tr><td>Folder Location:</td><td><input type='text' size='5' name='folder' value='".$settings['folder']."'/></td></tr>";
        echo "<tr><td>&nbsp;</td><td><input type='submit' name='PostSettings' value='Submit Form'/></td></tr></table>";
        echo "</form>";
and the php function to load and post variables

Code: Select all

if(isset($_POST['PostSettings'])){
            $settings['Enabled']        = (isset($_POST['Enabled']) && $_POST['Enabled'] == '1') ? 1 : 0;
            $settings['SystemName']     = $_POST['SystemName'];
            $settings['LicenseKey']     = $_POST['LicenseKey'];
            $settings['folder']         = $_POST['folder'];
            
            $message = "Details Saved";
            phpBB3SaveSetting($settings);
        }
Thanks for your help
User avatar
nor0101
Forum Commoner
Posts: 53
Joined: Thu Jan 15, 2009 12:06 pm
Location: Wisconsin

Re: HAving hard time with php(MySQL) and htmt _POST function

Post by nor0101 »

Not sure if it's your only problem but it looks like you've misplaced a right parenthesis in line 5 of your first example.

Instead of

Code: Select all

($settings['Enabled'] == '1' ? 'CHECKED' : '')
you might want

Code: Select all

($settings['Enabled'] == '1') ? 'CHECKED' : ''
Regards,
VicToMeyeZR
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 9:02 pm

Re: HAving hard time with php(MySQL) and htmt _POST function

Post by VicToMeyeZR »

Yeah I thought about that also.. All that does is print the word checked.
User avatar
nor0101
Forum Commoner
Posts: 53
Joined: Thu Jan 15, 2009 12:06 pm
Location: Wisconsin

Re: HAving hard time with php(MySQL) and htmt _POST function

Post by nor0101 »

Righto, "checked" is supposed to be its own attribute... in XHTML

Code: Select all

 
<input type="radio" name="fieldname" value="1" <?php if ($condition) { ?> checked="checked" <?php } ?>  />
 
VicToMeyeZR
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 9:02 pm

Re: HAving hard time with php(MySQL) and htmt _POST function

Post by VicToMeyeZR »

ok. yeah, I saw the checked, and realized I forgot that.

ok..

So I basically need 2 lines for that same check box?

Code: Select all

if $thisvariable {then <post this variable } else { <post this variable }
Does that sound right?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: HAving hard time with php(MySQL) and htmt _POST function

Post by Burrito »

Code: Select all

 
<tr><td>Enabled:</td><td><input type='checkbox' name='Enabled' ".($settings['Enabled'] == '1' ? "checked='checked'" : '')."'/></td></tr>
 
Post Reply