Dynamic Form Fields...
Notifications
Clear all

Dynamic Form Fields Array post to mySQL

RSS

(@abhijith)
Noble Member
Joined: 1 year ago
帖子:1350
15/05/2021 10:45 am

Dynamic Form Fields Array post to mySQL?


Quote
(@ganesh)
Noble Member
Joined: 1 year ago
Posts: 1362
15/05/2021 10:47 am

Looks like your widget is json encoding the form data - you'll need to decode it to process the contents

$pet_data=json_decode($_POST['petlist']['petlist'],true);

摘要h should give you ann array like this

$pet_data = Array ( [0] => Array ( [Pet Name] => Hal [Pet Type] => Dog [Breed] => Lab [DOB] => 02/10/2013 [Gender] => Male [Special Needs] => No ) [1] => Array ( [Pet Name] => Bill [Pet Type] => Dog [Breed] => Golden [DOB] => 03/20/2015 [Gender] => Male [Special Needs] => No ) )

You will need to reformat your dates before putting into your table (store as yyyy-mm-dd).

Why are you adding slashes to all your data? Use prepared queries with mysqli or PDO (preferred). The mysql_ library you are using is obsolete.

Why checkboxes for pet type? No one has a pet that is both cat and dog!.

Your data column types are overkill.

You'll find it more efficient to use INSERT … ON DUPLICATE KEY UPDATE... than your method of checking if it exists then inserting or updating.


ReplyQuote
Share:
Baidu