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.
Related
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":""}'
I really need your help To solve this array problem. Basically want to show each array values on wp data table. Its store on xampp wp_option table.
How can i use query to show them on data table.
Example of my databse: https://image.prntscr.com/image/Vna_-ux7T4mNEGPZAq1lrA.png
[Its shows the table column and rows]
Here are the example of my option_value json files .
{"id":1,"number":false,"input":"My table is now working","textarea":"Go to hell , you will find there","select":false,"radio":false,"hidden":false,"myFile":"C:\\\\fakepath\\\\FI.txt","fineuploader":false,"date":false,"checkbox":false,"button":false,"reset":false}
Its a json_encoded data. Now by global wpdb I want to show them in wordpress data table.
I just need the query through which i can loop all the keys and values and show them on data table.
Please help me on this.
I have a simple HTML form with three fields name,school and city. Also within the form, I have a button which I am using to insert a sub form with values neighbourhood and population. The crud mechanism is using jquery append.
In my database, I am saving the main form data in one table and the sub form data in another table.
My question is, during the creation of data in the main form, if I insert the data of the main form into one table and get the last inserted Id and use the id as a reference when inserting data into the second table, will this approach always work in both mysql and ms SQL?
If not is there a better approach I can adopt?
It will work, as long as your dynamically created input has the proper name attribute..
For example: name="txt_neighbourhood"
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 am saving data in a mysql database. This data is an array and the content is different data of the current user that is logged in to my system.
I do this when I save to the database:
$data = addslashes(serialize($array));
then
"UPDATE or INSERT INTO TABLE SET ... data = '$data';"
Now, the data are saved correctly since the insert or update statement return valid from my php code.
My problem is when I try to un-serialize it, it returns false and a notice is shown in my page.
What am I doing wrong?
I will bet the field in your mysql database is not big enough to save all the characters. That is why, when you un-serialize it you get an notice and nothing in return.
Try to increase the field to a MEDIUMBLOB or MEDIUMTEXT (maximum length of 16,777,215) or LONGBLOB or LONGTEXT (maximum length of 4,294,967,295) like this:
ALTER TABLE your_table MODIFY COLUMN column_name MEDIUMTEXT /* other properties*/;
And try to save and read your data again.
Now, if your data is over 4,294,967,295 (which is LONGBLOB or LONGTEXT), maybe you should check what kind of data you saving and maybe filter or remove unwanted some.
After you're getting the data from the table, are you removing the slashes before unserialize function.
Try inserting without the addslashes() and add slashes before it's taken to the array.