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