Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,581 members, 7,820,094 topics. Date: Tuesday, 07 May 2024 at 09:36 AM

How Can I Get Past This Mysql Error?.. I Need Help. - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How Can I Get Past This Mysql Error?.. I Need Help. (589 Views)

How To Integrate Paystack Payment Gateway In Website Using PHP and Mysql / How To Create An E-learning Website In HTML, CSS,PHP And Mysql / Adsense Approval Error. I Need Your Help. (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 3:58pm On Sep 28, 2018
I'm getting an error which says (cannot update or add a child row:a foreign key constraint fails).
I created two database table User and question.
TABLE user
User_Id. INT A.I primary key,
user_name .varchar
user_dob,
user_date, ..

Table question
Question_Id INT A.I,primary key,
Question_sub, varchar,
Question_date, date,
user_id INT (foreign key referencing user(user_I'd))
The problem is that whenever I try to insert into table (question) manually using phpadmin,it will be successful but whenever I try to insert into table (question) through php mysql always return the constraint fails error...
Re: How Can I Get Past This Mysql Error?.. I Need Help. by Bolaji21(m): 4:18pm On Sep 28, 2018
IBNgemini:
I'm getting an error which says (cannot update or add a child row:a foreign key constraint fails).
I created two database table User and question.
TABLE user
User_Id. INT A.I primary key,
user_name .varchar
user_dob,
user_date, ..

Table question
Question_Id INT A.I,primary key,
Question_sub, varchar,
Question_date, date,
user_id INT (foreign key referencing user(user_I'd))
The problem is that whenever I try to insert into table (question) manually using phpadmin,it will be successful but whenever I try to insert into table (question) through php mysql always return the constraint fails error...


Copy and paste the error here for details.
But constraint error means you're trying to insert into a column value greater than the constraint
For example, say you set the Question_sub as VARCHAR(20). if you're trying to insert a string in that column that's more than 20 characters, you'll get that error. A common error is trying to save a string in an INT column or a string in a DATE column
Re: How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 4:50pm On Sep 28, 2018
Bolaji21:

Copy and paste the error here for details.
But constraint error means you're trying to insert into a column value greater than the constraint
For example, say you set the Question_sub as VARCHAR(20). if you're trying to insert a string in that column that's more than 20 characters, you'll get that error. A common error is trying to save a string in an INT column or a string in a DATE column

Re: How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 4:52pm On Sep 28, 2018
Re: How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 4:59pm On Sep 28, 2018
Here is the mysql error output

Re: How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 5:03pm On Sep 28, 2018
Please webmasters.. I need your help on this..
Re: How Can I Get Past This Mysql Error?.. I Need Help. by Bolaji21(m): 12:21pm On Sep 30, 2018
The columns in the insert query doesn't match the table schema you posted earlier.
Also, change the quest_date column type to TIMESTAMP
quest_title column doesn't exist in the schema you posted earlier, but you're using it in your code

The mysql error you posted is pointing to foreign key, i assume you know what that is cos you must have added it yourself.
The data type for the child column must match the parent column exactly. For example, if user_id is a foreign key in question table and it's type INT, ID in user table must be INT.
Re: How Can I Get Past This Mysql Error?.. I Need Help. by IBNgemini: 8:12pm On Sep 30, 2018
Bolaji21:
The columns in the insert query doesn't match the table schema you posted earlier.
Also, change the quest_date column type to TIMESTAMP
quest_title column doesn't exist in the schema you posted earlier, but you're using it in your code

The mysql error you posted is pointing to foreign key, i assume you know what that is cos you must have added it yourself.
The data type for the child column must match the parent column exactly. For example, if user_id is a foreign key in question table and it's type INT, ID in user table must be INT.


Thanks a lot.I really appreciate. I have gotten where the constraint problem is coming from,the $_SESSION['user_I'd] isn't returning any value..I tried to echo it but nothing show,but other sessions like $_SESSION ['user_name] is working out fine apart the $_SESSION [user_I'd]...Anything I can do boss?...
Re: How Can I Get Past This Mysql Error?.. I Need Help. by Paulsamuel28: 6:28am On Oct 10, 2018
Hi

In case you are still stuck with this issue, then you can opt for a MySQL Database Repair Tool. It will help you to resolve several other issues present in it. Apart from that whichever MySQL versions you are using, comfortably you will be able to fix the issue present in it.

Also while using it, there is no need of prior installation of MySQL.

Evaluate its demo version which is very similar to its full version.

Thanks for reading.

(1) (Reply)

Emmanuel Ekainu Blog Setup Promo / My Experience And How Backing Up Helped Me / Approved And Functional Adsense Account Needed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.