close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Find Session Variable?

Thread began 2/10/2011 12:52 pm by willo009412397 | Last modified 2/23/2011 4:24 pm by Jason Byrnes | 2145 views | 18 replies |

willo009412397

Find Session Variable?

Hi
I have 2 problems there SecurityAssist & DataAssist combined, hope its ok too still post them here?. My 1st problem is Inserting into Multiple Tables, i have nearly worked it out but im lost as where to find the Session Variable?. I read a post here: showthread.php?t=18115&highlight=insert+tables

Which explains in a very clear way how too acheave this. I have created a customer backend, when they login the opening page is the UpdateProfile page. With a link from there to an options page , where they have an option to upload a Pet Ad (its a pet classifieds) i know form the post i read all i need to do is insert the Session Variable from either the Registration Page or the Update Profile Page but i cannot find it. Its needed because the 'ID' from the 2 tables im using will not be the same.

The 2nd problem is how too make it so as the customers can Upload more than 1 Ad?

thanks for any help, i have added the page`s also

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

Jason ByrnesWebAssist

the session from the profile age is named "id" if you dont see the id session variable listed in the Bindings Panel in the session section, you can create it:

go to Window -> Bindings to open the bindings panel

Click the Plus button to add a new binding

Select Session Variable and set the name to "id" (without the quotes, of course).

In the petdata table, you should have a user ID column that will be used as a foreign key column to relate each new record to the user that creates the record. this user ID column will get the value from the id session variable.




you have had a few questions about getting data from related tables, creating join queries, and I can see one flaw to your database design that is going to cause a lot of confusion for you, it actually already has.

In all of your tables you are naming the Primary key Column as "id". this can be confusing for a few reasons:

1) SecurityAssist uses the name of the id column to create the users id session variable. This has been created as "id" which is not a very informative session variable name, it does not tell you what the session variables job is.

2) you have to look at the table name to knwo which ID your referring to. you have already run into this issue in another thread where you where getting ambiguous column name error.

it is a better practice to use unique names for your columns in each table.

the naming convention I use when creating a new table is to include the table name in each column name. for example, if i am creating a new table name "users", i create all columns using "user" as a prefix:
userID
userFirstName
userLastName
userEmail
userPass

this way I have a unique name for every column in my database, the userID value will be stored in a session named userID, I will have be able to tell what the session is for at a glance and not have to keep track of it throughout the development process.

Sign in to reply to this post

willo009412397

Thanks for the advice on database structure i see now and it makes the job more easy. I should name as follows CustomerID and PetsID, if i change in my database now will it cause any problems for me at this stage?

And ref the Session Variable, the id is listed in the bindings. So what i need to do is open-up the Insert Record Wizard on the Insert Page and in the Session Variable box change it to id? is this right

Many thanks for your speedy reply

Sign in to reply to this post

Jason ByrnesWebAssist

Well, if you change column names now, you will need to change the names used in the pages that have already been created. I was more giving you the advice for future tables that you create.


Yes, in the insert record, bind to the id session variable.

Sign in to reply to this post

willo009412397

I have tried what you said, but its not worked for me. I have tried a few things i will explain what i have tried. In the `Insert Record Wizard` on my Insert Page i entered id into the SESSION VARIABLE-STORE AS it did not work.

so then i tried going into the code found WA_SESSION NAME="id"; and tried to bind it into where it says "id" the session variable looked like this- $_SESSION['id']; then i tested again but did not work.

Then the last thing i treid was within the `Insert Record Wizard` and at step2 tried to bind it to the 'id' there but not working.

Sorry Jason im hard work i know

Sign in to reply to this post

Jason ByrnesWebAssist

what exactly are you trying to do?

you want to store the value of the id session variable in a column of the petdata table right?

that column should be a foriegn key column your database, not the id column


dont set the store as column name to id, that will overwrite the users session variable when the record is inserted.


the users id should not be stored in the id column either.


you need another column to store the users id value in

in the insert record behavior, you select the column that will store the user id session variable in and click the lightning bolt next to value and select the id session variable.

Sign in to reply to this post

willo009412397

Overall what im trying to acheave is a Customer Backend, where the customer can update as many Pet Classifieds as they wish, with a results page that shows only there Classifieds. Before i even got started i knew i would have 3 major problems, as i know my limits with php.

1, In some way linking the 'id' value so in both the CustomerTable and the PetTable work together. As its is now if i Register and insert the pet info the results it shows on a search are not correct.
2, Working out a way for customers to be able to insert as many Ads as they want.
3, On the Results page within the customer backend, a way for it only to display results for that customer. At the moment it shows all within the database.

Probably very simple if you know what your doing, but sadly i do not...yet lol

Sign in to reply to this post

Jason ByrnesWebAssist

this is what I keep trying to get at.

the key to make this work is to have a foreign key column in the petdata table that draws the relationship to the users table


when deling with related data, you will encounter 2 diferant types of key columnns:

1) Primary Key - These are used to create a a unique value for each record in the table, every table needs to have one
2) Foreign Key - used in the child table to draw a relationship to another tables primary key.


in your users table, you have a primary key column called id.

you need to create a new column in the petdata table that will draw the relationship of pet to user.

for example sake, lets call this column petUserID

in the Insert Record Behavior, you need to bind the petUserID column to the id session variable. This will relate the pet data to the logged in user.


by using this foreign key column, you will create a one to many relationship and the customer will be able to add multiple ads.

Sign in to reply to this post

willo009412397

Hi Jason
Ok all week i have been on a Foreign Key mission, as i did not even know i needed one or know what one was lol. Thanks for putting me on the right track, i have the Database setup with a Relationship between the 2 tables. The relationship is between:

CustomerData (table1)
CustomerID- int(11)- Null=No- Default=None- Auto Increment

PetData (table2)
PetID- int(11)- Null=No- Default=None- Auto Increment
FKey- int(11)- Null=No- Default=None (this is the foreign key set as)
`petseen`.`customerdata`.`CustomerID`. CASCADE-CASCADE

On my Insert-Page i have binded the FKey to (CustomerID) in the parent table. But its not working i have been on a Mysql Forum and had guidence there that the Database structure is right. The only thing anyone could see was within the InsertPage code shown below:

<?php require_once('../Connections/petsCon.php'); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
{
$WA_connection = $petsCon;
$WA_table = "petdata";
$WA_sessionName = "WADA_Insert_petdata";
$WA_redirectURL = "petdata_Results.php";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_indexField = "PetID";
$WA_fieldNamesStr = "Fkey|Type|Breed|Age|Colour|Price|SalesPoint|Description|Image1|Image2|VideoClip";
$WA_fieldValuesStr = "".$_SESSION['CustomerID'] ."" . "|" . "".((isset($_POST["Type"]))?$_POST["Type"]:"") ."" . "|" . "".((isset($_POST["Breed"]))?$_POST["Breed"]:"") ."" . "|" . "".((isset($_POST["Age"]))?$_POST["Age"]:"") ."" . "|" . "".((isset($_POST["Colour"]))?$_POST["Colour"]:"") ."" . "|" . "".((isset($_POST["Price"]))?$_POST["Price"]:"") ."" . "|" . "".((isset($_POST["SalesPoint"]))?$_POST["SalesPoint"]:"") ."" . "|" . "".((isset($_POST["Description"]))?$_POST["Description"]:"") ."" . "|" . "".((isset($_POST["Image1"]))?$_POST["Image1"]:"") ."" . "|" . "".((isset($_POST["Image2"]))?$_POST["Image2"]:"") ."" . "|" . "".((isset($_POST["VideoClip"]))?$_POST["VideoClip"]:"") ."";
$WA_columnTypesStr = "none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_petsCon;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);

Only thing anyone could find was here - if (!session_id()) session_start(); i was advised that the session_start(); part should be at the top of page?I have not tried it , i thought best to ask here 1st.

When i try to insert a record i get this error--Column 'Fkey' cannot be null

thankyou for anyhelp

Sign in to reply to this post

Jason ByrnesWebAssist

1) You should snot set the fkey column to be a foreign key type in the table itself.

this is not needed to _use_ the column as a foreign key column.


2) The error is saying theat the session $_SESSION['CustomerID'] does not have a value.


you can try adding:
<?php if(!session_id()) session-start(); ?> at line one of the page, if that does not work, track down where $_SESSION['CustomerID'] is supposed to get set to look into why iot is not getting set.

Sign in to reply to this post
loading

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...