close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Need help storing variable in table

Thread began 4/09/2012 2:54 pm by Dennis | Last modified 4/10/2012 7:37 pm by Dennis | 1356 views | 8 replies |

Dennis

Need help storing variable in table

Hi,

With my WADA Insert, Update & WASA Profile pages I would like to store a field in the database based on a field in the form.

From the two digit State entered on the form I would like a Region field in the database table updated. Might I be able to select this Region from a short list of arrays such as…

php:
<?php

$eastern 
= array('CT''DE''DC''ME''MD''MA''NH''NJ''NY''PA''RI''VT''QC''NL''PE''NS''NB');
$southern = array('AL''FL''GA''LA''MS''NC''SC''VA''WV');
$central = array('IL''IN''KY''MI''OH''TN''WI''ON');
$great_plains = array('AR''CO''IA''KS''MN''MO''MT''NE''NM''ND''OK''SD''TX''WY''MB''SK''NT');
$western = array('AK''AZ''CA''HI''ID''NV''OR''UT''WA''AB''BC''YT');
  
if (
in_array($row_WAATKmemberaccounts['State'],$eastern))
    
$region 'Eastern';
elseif (
in_array($row_WAATKmemberaccounts['State'],$southern))
    
$region 'Southern';
elseif (
in_array($row_WAATKmemberaccounts['State'],$central))
    
$region 'Central';
elseif (
in_array($row_WAATKmemberaccounts['State'],$great_plains))
    
$region 'Great Plains';
elseif (
in_array($row_WAATKmemberaccounts['State'],$western))
    
$region 'Western';
else
    
$region 'International';
?>



Does the above code look correct/usable?

But now I don&#8217;t know how to get my variable $region stored into the table field labeled Region.

Your help would be appreciated

Note: this question is similiar to my post post #118796 however I dodn't have the skills to adapt the suggested tutorial.

Thanks,
Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

there are a few problems with your code:

1) the format of your if, elseif statement is not correct.

an if statement should be formatted as:

if(condition) {
do something
} elseif(condition) {
do something else
} else {
do another something
}

your if statement is missing the "{" and "}"

2) instead of setting an application variable:
$region

use a session variable:
$_SESSION['region'] = 'Eastern';

3) in your if statement, don't use the state recordset column:
in_array($row_WAATKmemberaccounts['State']),$eastern)

instead, use the state form element, assuming the form element is named State:
in_array($_POST['State']),$eastern)

4) go to the bindings panel, click the plus button and select Session Variable, name the session binding "region". In the insert behavior, bind the region column to the region session variable.

Sign in to reply to this post

Dennis

Thank You Jason,

However I am having problems that appear to be due to using the form element name.

In fact if I add (<?php echo $_POST["State"]; ?>) the page displays ()

Here is the code in the form to enter the state...
<tr><th>State:</th>
<td><input type="text" class="WAATKTextField" name="State" id="State" value="<?php echo(str_replace('"', '&quot;', $row_WAATKmemberaccounts['State'])); ?>" size="32" /></td></tr>

I have tried this with both the profile page from WASA and the update page from WADA. And with other form element names, placing the echo statement within and outside the form tags. And with single or double quotes around the form element name in the echo statement.

Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

please provide more details, are you getting an error message? if so what is the error.

Sign in to reply to this post

Dennis

In my localhost (WampServer) environment i get "Notice: Undefined index: State in ..." the line number matches the first line of my if statement

php:
<?php

$eastern 
= array('CT''DE''DC''ME''MD''MA''NH''NJ''NY''PA''RI''VT''QC''NL''PE''NS''NB');
$southern = array('AL''FL''GA''LA''MS''NC''SC''VA''WV');
$central = array('IL''IN''KY''MI''OH''TN''WI''ON');
$great_plains = array('AR''CO''IA''KS''MN''MO''MT''NE''NM''ND''OK''SD''TX''WY''MB''SK''NT');
$western = array('AK''AZ''CA''HI''ID''NV''OR''UT''WA''AB''BC''YT');
  
if (
in_array($_POST['State'],$eastern)) {
    
$_SESSION['membersRegion'] = 'Eastern';
} else {
    
$_SESSION['membersRegion'] = 'International';
}
?>



No error on the remote server but the if statement fails, the reponse is always "International" when I insert any of the state codes in the $eastern array in the "State" field of the form.

Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

please send a copy of the page so I can see the code in context.

Sign in to reply to this post

Dennis

Attached.

Thanks,
Dennis

Attached Files
member_Profile.zip
Sign in to reply to this post

Jason ByrnesWebAssist

you cant set a varibale based on the post untill the form is sent


use this code:

php:
<?php

$eastern 
= array('CT''DE''DC''ME''MD''MA''NH''NJ''NY''PA''RI''VT''QC''NL''PE''NS''NB');
$southern = array('AL''FL''GA''LA''MS''NC''SC''VA''WV');
$central = array('IL''IN''KY''MI''OH''TN''WI''ON');
$great_plains = array('AR''CO''IA''KS''MN''MO''MT''NE''NM''ND''OK''SD''TX''WY''MB''SK''NT');
$western = array('AK''AZ''CA''HI''ID''NV''OR''UT''WA''AB''BC''YT');
if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "WAATKUpdateForm")) {
if (
in_array($_POST['State'],$eastern)) {
    
$_POST['Region'] = 'Eastern';
} else {
    
$_POST['Region'] = 'International';
}
}
?>



to set the region form element, and put it at line 1 of your page.

Sign in to reply to this post

Dennis

Thank You

Jason,

Appears to be working.

Thank you very much for your help. I have been trying to get that to work for months.

Dennis

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...