Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Foreign Key

Author  Topic 

Shoapin
Starting Member

1 Post

Posted - 2012-02-26 : 11:01:04
I need help with the foreign key, this is the php portion of my site to insert records, i am testing so i am only entering one. When i hit the creat account button it sends me to another page to insert additional info. I add info to the first page no problem but when i add to the 2nd page and submit i get the error: Cannot add or update a child row: a foreign key constraint fails (`search_info`.`properties`, CONSTRAINT `properties_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `information` (`customer_id`) ON DELETE CASCADE ON UPDATE CASCADE). Can someone help please?

1st Page NewAccount
DATABASE INFO - Table name Information
# Column Type Collation Attributes Null Default Extra Action
1 custId int(11) No None AUTO_INCREMENT Change Drop More
2 Username varchar(25) latin1_swedish_ci No None Change Drop More
INDEXES
Action Keyname Type Unique Packed Column Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No custId 1 A


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "newAccount")) {
$insertSQL = sprintf("INSERT INTO information (Username) VALUES (%s)",
GetSQLValueString($_POST['accUser'], "text"));

mysql_select_db($database_PropertyConnect, $PropertyConnect);
$Result1 = mysql_query($insertSQL, $PropertyConnect) or die(mysql_error());

$insertGoTo = "listingType.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

2nd Page Additional Info
DATABASE INFO - Table name properties
# Column Type Collation Attributes Null Default Extra Action
1 propId int(11) No None AUTO_INCREMENT Change Drop More
2 FirstName varchar(25) latin1_swedish_ci No None Change Drop More
3 custId int(11) No None Change Drop More

INDEXES


Action Keyname Type Unique Packed Column Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No propId 0 A
Edit Drop custId BTREE No No custId 0 A


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "freeList")) {
$insertSQL = sprintf("INSERT INTO properties (FirstName) VALUES (%s)",
GetSQLValueString($_POST['freeCountryList'], "text"));

mysql_select_db($database_PropertyConnect, $PropertyConnect);
$Result1 = mysql_query($insertSQL, $PropertyConnect) or die(mysql_error());

$insertGoTo = "freeRegistration.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-26 : 12:40:18
cant help much seeing posted query. To make a start you need to check what values you're passing from second screen to save and check if its preserving referential intehrity ie pointing to a valid record in parent tables.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Jayam.cnu
Starting Member

45 Posts

Posted - 2012-02-27 : 05:03:31
if possible post list table details with definitions........ may be that will help full to get the solutions...
Go to Top of Page
   

- Advertisement -