+ 1

Problem with PHP connection to MySQL tables

Hi everyone. My problem is this: - on the back-end I have database in MySQL. It contains 7 tables. - On the front-end I have a HTML form. - The data entered from the user must populate these 7 tables. - I use PHP and link the form to database with mysqli. For some reason the form populated only the first table and the other 6 received no data. Any idea how I can connect the form to all tables at once? I don’t want one sql table, because the HTML form has over 300 input fields. Thanks you.

17th Dec 2018, 11:00 PM
pap
pap - avatar
11 ответов
+ 3
i figer it out! there where 2 issues: 1) issue one - the tables were not created right and the foreign key was false connected. i have a problem with creating tables with foreign key through phpmyadmin menu. maybe it is better to use the sql database and table creation syntax: https://code.sololearn.com/W16zHYaY0bvQ/?ref=app PLEASE NOTE: the foreign key variable must be added in both tables (i know it is obvious, but still). 2) there was a failure in the php code. i missed in the prepared statemnt the input in the foreign key collumn in the second table, namelly: $stmt=$link->prepare("INSERT INTO table_pre (height, weight) VALUE (?, ?)"); $stmt->bind_param("ii", $height, $weight); instead of: $stmt=$link->prepare("INSERT INTO table_pre (height, weight, admission_no) VALUE (?, ?, ?)"); $stmt->bind_param("iii", $height, $weight, $adm_no);
27th Dec 2018, 6:13 PM
pap
pap - avatar
+ 3
Michal Dudek you were right the foreign key was not correct. i dropped all the tables and made the again from scrap. now i receive an error the there is a mistake in the second “prepared” statment. i updated also the html code. thanks for your support and help https://code.sololearn.com/WKYfwAUEan2g/?ref=app https://code.sololearn.com/w5qA64ZJ76Fa/?ref=app
23rd Dec 2018, 12:47 AM
pap
pap - avatar
+ 2
Michal Dudek it still not working :( :( any ideas why?
25th Dec 2018, 1:14 PM
pap
pap - avatar
+ 1
One frontend form have 300 inputs??! There is something wrong! OK, come back to problem. 1) All data store in some array, you can also use POST (it is array itself). 2) Firstly write by your script data in tables which NO contains any Foreign Key, because of, you can have problem with FK missing while you wanna write data. 3) Write in to other tables by hierarchy, so if you have 2 tables where table A depend on table B, firstly write data to table B and after that write on table A. Better options: Show me your SQL Create script or DB dump and PHP script for gathering data and writing to DB.
18th Dec 2018, 9:25 PM
Michal Dudek
Michal Dudek - avatar
+ 1
Michal Dudek 1) i use post. those are sensitive data. plus get have a limit. 2) i cant actually understand this one :( the data are related - i need a connected tables. those are customers. table 1 - demography (client number as PRIMARY KEY, name, sex etc.) table 2 is other data - education, religion, and so on. the FOREIGN KEY here must be the PRIMARY from the table 1 (client number). i cant continue to add data when those are jot connected. for now i have this small test Database with 3 test tables just to check the isertion process by testing. most of the data in the form are radio buttons - meaning INT (1). excuse my english. i hope i explained it clear enough. thanks here is my php code: https://code.sololearn.com/w5qA64ZJ76Fa/?ref=app
18th Dec 2018, 9:51 PM
pap
pap - avatar
+ 1
Michal Dudek inmade them with phpmyadmin in XAMPP
19th Dec 2018, 9:16 AM
pap
pap - avatar
+ 1
Michal Dudek i will try to post a screenshot of the database structure. thanks for your help!
19th Dec 2018, 11:55 AM
pap
pap - avatar
+ 1
Michal Dudek i used this statement in SQL tab of myphpadmin: ALTER TABLE table_pre ADD FOREIGN KEY (id_pre) REFERENCES table_demo (id);
19th Dec 2018, 10:33 PM
pap
pap - avatar
+ 1
pap I'm not more wise from your comment. Please: phpMyAdmin — How to backup or export a database or table 1) Log into phpMyAdmin. 2) Select the source database on the left pane. 3) Click on the Export tab in the top center pane. On the next page you must select a Quick or Custom export method. ...From the dropdown menu, choose the format (SQL) 4) ...Click the Go button to continue. 5) Send me SQL for both table which will start something like CREATE TABLE (name) IF NOT EXIST up to end of text.
20th Dec 2018, 3:59 PM
Michal Dudek
Michal Dudek - avatar
0
Can you show me how are tables made? Like SQL create script or db dump. Thanks.
19th Dec 2018, 7:46 AM
Michal Dudek
Michal Dudek - avatar
- 1
Ok. Thats no problem to export them in to SQL Dump. I just would like to see how FK are made. I think problem could be there.
19th Dec 2018, 9:22 AM
Michal Dudek
Michal Dudek - avatar