Jump to content

[SOLVED] Error: (1452) Cannot add or update a child row:


Recommended Posts

Okay I am simply trying to update a record here is the error I get

 

A fatal MySQL error occurred.

Query: UPDATE Profile_Appearance SET Height='4', Weight='', HairColor='1', EyeColor='7', Build='6', FacialHair='7', Tattoos='5', Piercings='4' WHERE CustID ='539717990'

Error: (1452) Cannot add or update a child row: a foreign key constraint fails (`alpha_cms/Profile_Appearance`, CONSTRAINT `FK_Profile_Appearance_Build` FOREIGN KEY (`Build`) REFERENCES `answ_build` (`BuildID`))

 

<?php
session_start();
//Get User's CustID
if (isset($_SESSION['CustID'])) {
$varCustID = $_SESSION['CustID'];

// Connect to DB
include('/home/thegayestever/thegayestcommunityever.com/projects/recode/php/includes/configs/db_config.php');

$varProfileAppearanceArray = mysql_query("SELECT * FROM Profile_Appearance WHERE CustID = '$varCustID'");

$varPrevAppearance = mysql_fetch_assoc($varProfileAppearanceArray);

$varPrevHeight = $varPrevAppearance[Height];
$varPrevWeight = $varPrevAppearance[Weight];
$varPrevHairColor = $varPrevAppearance[HairColor];
$varPrevEyeColor = $varPrevAppearance[EyeColor];
$varPrevBuild = $varPrevAppearance[build];
$varPrevFacialHair = $varPrevAppearance[FacialHair];
$varPrevTattoos = $varPrevAppearance[Tattoos];
$varPrevPiercings = $varPrevAppearance[Piercings];

mysql_close($con);
} else {
header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=denied");
}

print "<div id=\"profileupdater\">
<form method=\"post\" name=\"Profile_About\" action=\"php/includes/content/members_home/forms/profile_forms/post_profile_appearance_form.php\">
<fieldset id=\"first2\">
<legend for=\"appearence\">APPEARANCE </legend>
		<ol>
                <li><label for=\"height\">	Height:	</label>	
				<select id=\"height\" name=\"formHeight\" >";
					include('includes/height.php');
				echo "</select>
			</li>
                <li><label for=\"weight\">	Weight:	</label>	<input id=\"weight\" type=\"text\" name=\"formWeight\" maxlength=\"3\" value=\"$varPrevWeight\" /></li>
                <li><label for=\"haircolor\">Hair Color:</label>
                		<select id=\"haircolor\" name=\"formHairColor\">";
                            include('includes/haircolor.php');                        
                        echo "</select>             	
                </li>
                
                <li><label for=\"eyecolor\">	Eye Color:</label>	
                		<select id=\"eyecolor\" name=\"formEyeColor\">";
		                include('includes/eyecolor.php');
                        echo "</select>    
                </li>
                
                
                <li><label for=\"build\">	 Build:</label>	
                		<select id=\"build\" name=\"formBuild\">";
		                include('includes/build.php');
                        echo "</select>    
                </li>
                
                <li><label for=\"facialhair\">Facial Hair:</label>	
                		<select id=\"facialhair\" name=\"formFacialHair\">";
		               include('includes/facialhair.php');
                        echo "</select>    
                </li>
                
                <li><label for=\"tattoos\">Tattoos:</label>	
                		<select id=\"tattoos\" name=\"formTattoos\">";
		                include('includes/tattoos.php');
                        echo "</select>    
                </li>
                
                <li><label for=\"piercings\">Piercings:</label>
                		<select id=\"piercings\" name=\"formPiercings\">";
                        	include('includes/piercings.php');
                        echo "</select>
                </li>      
    		</ol>
		<input type=\"submit\" value=\"Update Profile Now!\"/>
</fieldset>

</form>
</div>"
?>

 

Any Ideas guys, this is my first attempt at relationships in databases so if I am missing information please let me know what you need.

 

Thanks :)

Maybe im missing something but does the code you posted even have anythign to do with the error your getting ?

 

The error seems to point to a UPDATE query, yet the code you posted only has a SELECT Query..

 

 

I think no one has responded to your thread because of what i just said, and it may make people feel like its a waste of time, when it looks like you dont understand the code you are presenting....do you ?

 

What relationship does the code u present have with the error u gave ?

 

http://www.rojakcoder.com/wordpress/2008/12/17/mysql-error-1452/  <--possible explination ?

Thanks Dark here is the rest of the code with the update statement:

 

<?php
session_start();
// APPEARANCE
$varHeight = $_POST['formHeight'];
$varWeight = $_POST['formWeight'];
	$varHairColor = $_POST['formHairColor'];
$varEyeColor = $_POST['formEyeColor'];
$varBuild = $_POST['formBuild'];
$varFacialHair = $_POST['formFacialHair'];
$varTattoos = $_POST['formTattoos'];
$varPiercings = $_POST['formPiercings'];

// Get CustID from cookie
if (isset($_SESSION['CustID'])) {
$varCustID = $_SESSION['CustID'];

// Connect to DB
include('/home/thegayestever/thegayestcommunityever.com/projects/recode/php/includes/configs/db_config.php');

//Store APPEARANCE
$query = "UPDATE Profile_Appearance SET Height='$varHeight', Weight='$varWeight', HairColor='$varHairColor', EyeColor='$varEyeColor', Build='$varBuild', FacialHair='$varFacialHair', Tattoos='$varTattoos', Piercings='$varPiercings' WHERE CustID ='$varCustID'";
$result = @mysql_query($query) 
or die("<b>A fatal MySQL error occurred</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());


mysql_close($con);
} else {
	header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=profileupdateall");
}
if ($pageid =='0') {
	header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=members_home");
} else 
	header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=profileupdateall");


//BasicS
/*$varHeadline = $_POST['formHeadline'];
$varCountry = $_POST['formCountry'];
$varZipCode = $_POST['formZipCode'];
$varState = $_POST['formState'];
$varGender = $_POST['formGender'];
$varBirthdate = $_POST['formBirthdate'];
$varSexuality = $_POST['formSexuality'];
$varInterestedIn = $_POST['formInterestedIn'];
$varRelationshipStatus = $_POST['formRelationshipStatus'];
$varHIVStatus = $_POST['formHIVStatus'];
$varEthnicity = $_POST['formEthnicity'];

// Get CustID from cookie
$varCustID = $_COOKIE['CustID'];
// Connect to DB
include('/home/thegayestever/thegayestcommunityever.com/projects/recode/php/includes/configs/db_config.php');

//Store BasicS
mysql_query("UPDATE profile_Basic SET Headline='$varHeadline', Country='$varCountry', ZipCode='$varZipCode', State='$varState', Gender='$varGender', Birthdate='$varBirthdate', Sexuality='$varSexuality', InterestedIn='$varInterestedIn', RelationshipStatus='$varRelationshipStatus', HIVStatus='$varHIVStatus', Ethnicity='$varEthnicity' WHERE CustID='$varCustID'");

mysql_close($con);

if ($pageid =='0') {
	header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=members_home");
} else 
	header ("Location: http://www.thegayestcommunityever.com/projects/recode/index.php?section=profileupdateall");*/
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.