Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:51:12+00:00 2026-05-30T12:51:12+00:00

I have two tables: candidate_register_table with the following schema: |—————————————————-| | username | name

  • 0

I have two tables:

candidate_register_table with the following schema:

|----------------------------------------------------|
|   username  |  name   |  age   | sex   | password  |
|----------------------------------------------------|

candidate_social_table with the following schema

|--------------------------------------------------------|
|   username  |  religion   | caste  | address   | city  |
|--------------------------------------------------------|

In both tables, username are primary keys in their corresponding table.

I want to insert data in both the table in a single click event, where the username in table candidate_register_table is a foreign key in candidate_social_table also

This is my reg_conn.php where the data are getting inserted:

<?php
include('connection.php')'

$sql_register="INSERT INTO candidate_register_table (username, name, age, sex, password) )           VALUES('$_POST[username]','$_POST[name]','$_POST[age]', '$_POST[sex]','$_POST[password]')";
$sql_social_disable="ALTER TABLE candidate_social_table disable CONSTRAINT fk_candidate_register_table";
$sql_social="INSERT INTO candidate_social_table (username) VALUES('$_POST[username]')";
$sql_social_enable="ALTER TABLE candidate_social_table enable CONSTRAINT fk_candidate_register_table";

if(mysql_query($sql_register,$con) && mysql_query($sql_social_disable,$con) && mysql_query($sql_social,$con)  && mysql_query($sql_social_enable,$con))
   { echo "you have been registered";
   }
else
   {
       die('Error: ' . mysql_error());
       echo "Something went wrong. Might be a Fatal Error";
   }
?>

Now the problem is that, my connection and all others are all working perfectly, but the query:

ALTER TABLE candidate_social_table disable CONSTRAINT fk_candidate_register_table`

Is not getting executed, its throwing the following error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT fk_t1' at line 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:51:14+00:00Added an answer on May 30, 2026 at 12:51 pm

    I’m not sure if you can disable a constraint for a single table, or why you need to disable the foreign key in the first place since you are inserting your data in the correct order – but you can try:

    $sql_social_disable="SET FOREIGN_KEY_CHECKS=0";

    to re-enable, use

    $sql_social_disable="SET FOREIGN_KEY_CHECKS=1";

    Alternatively, you can drop the specific foreign key constraint, then recreate it when you are done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, like these: Table People: VARCHAR Name INTEGER Age Table Message
I have two tables users(id, username, password) and user_badges(user_id, badge_id, badge_slot) I would like
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
I have two tables: TableA ( ID [int, pk], Name [string]) and TableB (ID
I have two tables: COUNTRY ------------- id name NEIGHBOUR ------------- id id_country1 id_country2 id_country1
I have two tables ITEMS : id, name CATEGORIES: items_id, category I need to
I have two tables: Table1: id attr1 fk1(Table2) fk2(Table2) Table2: id name I want
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.