Jump to content

Insert data error...


tshing70
 Share

Recommended Posts

I have a table name collection withc_id int PK AUTO_INCREMENT,memberid int FK,date date,amount Numeric (12,2),refno VARCHAR(20), my FK references to my 1st table PK, name P_Id I want to add date, amount and refno,but when i click add it show me INSERT INTO collection (date, refno, amount) VALUES ('03/07/2012','345','234')Error: Cannot add or update a child row: a foreign key constraint fails (`member_db`.`collection`, CONSTRAINT `collection_ibfk_1` FOREIGN KEY (`memberid`) REFERENCES `newmember` (`P_Id`)) Anyone help pls.... :facepalm: Add.html<html><head><title>Add Info</title><link rel="stylesheet" type="text/css" href="tcal.css" /><script type="text/javascript" src="tcal.js"></script></head><body><form action = "add.php" method="post"><center><table width="250" border="1"><tr valign="top"><td style="background-color:white;width:100px;text-align:top;"><p>Date<p>Reference No<p>Amount</td><td style="background-color:#EEEEEE;height:200px;width:1000px;text-align:top;"><input type ="date" name="date" class="tcal" value=""/><p><input type ="text" name="refno"><p><br><input type ="number" name="amount"><p><input type ="submit" value="Add"></td></tr></form></table></center></body></html> Add.php<?php$con = mysql_connect("localhost","root","");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("member_db", $con);$sql="INSERT INTO collection (date, refno, amount)VALUES ('$_POST[date]','$_POST[refno]','$_POST[amount]')";echo $sql;if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";echo "<br>";echo "<a href='edit.php'>Back to Edit page</a>";mysql_close($con);?>

Link to comment
Share on other sites

similar problem like youhttp://w3schools.invisionzone.com/index.php?showtopic=44261

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...