Page 1 of 1

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

Posted: Thu Jan 15, 2009 9:04 pm
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

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

Posted: Thu Jan 15, 2009 11:56 pm
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,

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

Posted: Fri Jan 16, 2009 8:35 am
by VicToMeyeZR
Yeah I thought about that also.. All that does is print the word checked.

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

Posted: Fri Jan 16, 2009 10:47 am
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 } ?>  />
 

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

Posted: Sat Jan 17, 2009 1:04 pm
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?

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

Posted: Sat Jan 17, 2009 2:53 pm
by Burrito

Code: Select all

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