While creating an invoice system, I have the code to add or remove the text box and section it's working fine. Once I try to save the data to MySQL its not working. I tried to insert the JSON output.
it's the JSON output of $_POST
{"sectionName":{"1":"1","2":"2"},"productCode":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"productName":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"quantity":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"price":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"notes":"","userId":"123456","invoice_btn":"Save Invoice","subTotal":"6","taxRate":"","taxAmount":"","totalAftertax":"","amountPaid":"","amountDue":""}
I not getting any idea how to insert this data to mySQL
can u provide ur sql field? like field name and type.
but if its data string and wanna insert it on single field, try wrap ur json with single quotes like
'{"sectionName":{"1":"1","2":"2"},"productCode":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"productName":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"quantity":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"price":{"1":{"1":"1","2":"2"},"2":{"1":"1","2":"2"}},"notes":"","userId":"123456","invoice_btn":"Save Invoice","subTotal":"6","taxRate":"","taxAmount":"","totalAftertax":"","amountPaid":"","amountDue":""}'
Related
I am currently storing JSON data in a gzipped LONGBLOB column. I want to change this column to a JSON column so that O can use the JSON functions in MySQL.
However, when I tried to insert a row using MySQL with a JSON column, I realised that the insert_id was always 0 and all the inserts failed. I then checked the PHP MySQLi documentation and realised that send_long_data (which I was using to send the JSON data) is only usable for TEXT and BLOB columns.
Is there an alternative to send_long_data which works for JSON columns? Sending the JSON data using bind_param and a string would not work as I believe most of my data would exceed max_allowed_packet.
You can do this, but it's bad practice:
Create a TEXT field, insert data into it, and then use UPDATE to copy the data from the TEXT field to JSON, then clear the TEXT field through UPDATE.
Edited Question:
Thank You for your answers. Sorry for that i am not really looking as per your answers. I want multiple insertion from textarea box while form submission.
i have this result. i want to insert multiple data (both column and rows) into mysql table using (textarea box) (on form submission)
when we copy above data to textarea box its look like below
following source link already done with single column values.. But i want to insert two column values same time in mysql.
https://www.webslesson.info/2019/06/how-to-insert-multiple-data-into-mysql-in-php-using-textarea-field.html
Any one help me for code
i found two discussion page here below same like my question
How to insert multiple row from textarea to multiple column?
How to insert multiple value and Multiple rows from textarea to MySQL using PHP?
---- but from above no answer posted properly...
For eg:
I want to insert following two columns (state,distance(miles) in mysql using textarea box.
Firstly, you have to use <form></form> tags around the table.
Then to get values of each columns in a row, you can use some <input> tags inside the <td> tags. The reason why doing this is because <td> tags don't have a name attribute and thus cannot use php $_GET or $_POST variables
Once you have the name attribute, use $_POST or $_GET to capture and transfer to database
You can check this link. This will give you some insight
Link here
When I insert the serialize data in the postmeta table the data is modified while inserting like:
s:107:"a:4:{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}";
but when I print this data before inserting it is displaying this that is right:
a:4:{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}
while inserting it is automatically add string count s:107:" in front of data or "; in back of data.
Please suggest me how i resolve this.
When I insert the serialize data in the postmeta table the data is modified while inserting like:
s:107:"a:4:{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}";
but when I print this data before inserting it is displaying this that is right:
a:4:{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}
while inserting it is automatically add s:107:" in front of data or "; in back of data.
Can any one please tell me why it is inserting like this.
Thanks in Advance
The s means string.
107 stands for the size of the string.
I want to actually import the .csv file to a database, my problem is that when I validate the data of excel sheet, only actual data should get inserted to the database. If one of the row does not match with the actual data type then it should show the message this rows can not be insert in to database using only php.
http://php.net/manual/en/function.fgetcsv.php sometimes manuals are good. :)