Skip to main content
Inspiring
July 5, 2012
Answered

dreamweaver checkbox update problem

  • July 5, 2012
  • 2 replies
  • 1180 views

Hello

I have a basic checkbox on a form that is not updating

when the box is checked it is updating the PHP DB but when i go back into the form the check box is not showing the correct value

php is

GetSQLValueString(isset($_POST['BankFinCCJ']) ? "true" : "", "defined","'Y'","'N'"),

form value

<input type="checkbox" name="BankFinCCJ" <?php if (!(strcmp(htmlentities($row_Recordset1['BankFinCCJ'], ENT_COMPAT, 'utf-8'),"true"))) {echo "checked=\"checked\"";} ?> />

what am i doing wrong? can anyone help?

This topic has been closed for replies.
Correct answer David_Powers

Your form should look like this:

<input type="checkbox" name="BankFinCCJ" <?php if (!(strcmp($row_Recordset1['BankFinCCJ'],"Y"))) {echo "checked=\"checked\"";} ?> />

You have misunderstood the following line:

GetSQLValueString(isset($_POST['BankFinCCJ']) ? "true" : "", "defined","'Y'","'N'")

The GetSQLValueString() function takes up to four arguments. The first one is the value, the second is the type. And if the type is "defined", it takes two more arguments: the defined value, and the not-defined value.

The first argument to the function is this:

isset($_POST['BankFinCCJ']) ? "true" : ""

What that means is that if $_POST['BankFinCCJ'] exists, the value passed to GetSQLValueString() is "true". If it doesn't exist, an empty string is passed to the function. The "true" value is used internally by GetSQLValueString(). The actual values are "Y" and "N". That's why you need to test for "Y", and not for "true".

2 replies

David_Powers
David_PowersCorrect answer
Inspiring
July 5, 2012

Your form should look like this:

<input type="checkbox" name="BankFinCCJ" <?php if (!(strcmp($row_Recordset1['BankFinCCJ'],"Y"))) {echo "checked=\"checked\"";} ?> />

You have misunderstood the following line:

GetSQLValueString(isset($_POST['BankFinCCJ']) ? "true" : "", "defined","'Y'","'N'")

The GetSQLValueString() function takes up to four arguments. The first one is the value, the second is the type. And if the type is "defined", it takes two more arguments: the defined value, and the not-defined value.

The first argument to the function is this:

isset($_POST['BankFinCCJ']) ? "true" : ""

What that means is that if $_POST['BankFinCCJ'] exists, the value passed to GetSQLValueString() is "true". If it doesn't exist, an empty string is passed to the function. The "true" value is used internally by GetSQLValueString(). The actual values are "Y" and "N". That's why you need to test for "Y", and not for "true".

Inspiring
July 5, 2012

I understand, so basically what ever value you are using to store in the DB is the value that needs to be checked so we are using y and N if we were storing truw and flase we would check these values?

thats was a great help thank you

David_Powers
Inspiring
July 5, 2012

Yes, it's the value that's stored in the database that matters.

David_Powers
Inspiring
July 5, 2012

Please don't post duplicate threads with what is essentially the same question. I have deleted your original thread.

I think I know what is wrong with your code, but I need to check how GetSQLValueString() handles user-defined values first.

Inspiring
July 5, 2012

sorry for the duplicate post, i made one late last night and wasnt sure i covered what i was trying to get across

do you need anything from me?

David_Powers
Inspiring
July 5, 2012

No, I think that my answer above should cover everything.

If you don't get an answer to a post, and think that more information might be needed, just add to the original thread. It makes it much easier for everyone if all related issues are kept in one thread.