-
how can i insert a value into foreign key in mysql table using php?
about 8 years ago
-
about 8 years ago
Hello Nasyia,
I have checked your code and I can see you are getting data from programming_language table then outside the while loop you are inserting the data. You need to put the insert query inside the while loop to store all the language id. If you put the insert query outside the loop then only last value will be inserted. If you are still facing problem or you are getting any specific error then send us the error which are you getting?
Hope this helps!
Deepak Verma Sr. Software Engineer
-
-
about 8 years ago
Hello Nasyia if your select statment return one row then you can try this way
" name="language_id"> submit.php -
-
about 8 years ago
Hello Nasyia, In above code, i think the select statement returns more than 1 language_id but you have declared it as a variable first make it an array then try to insert this in test table. Please check it and inform me if you still face some issue.
-
-
about 8 years ago
Hello Nasyia,
If you are adding data in test table then there should be a form to fill the data to insert. You need to contain all the language in a drop-down with their ids. After form submission you can get the form data and pass these data in query to insert.
Hope this helps!
Deepak Verma Sr. Software Engineer
-
-
about 8 years ago
Hello !! Thank you for your help , but these codes are written in different pages and values in programming languages are stored in the database already, but I need to insert the id of the programming languages whenever you want to add a new test so how can i insert the id i found method called the last id but its using when you adding new rows but my values are already stored i hope i made it clear for you
-
5 Answer(s)