r/PHPhelp • • Mar 20 '26
How to I convert variable into usable data for $_POST?
I have data I need written to a table stored in variables, but I can't get the code to write it to the table for some reason. I think it's because the data has to use the $_POST function, but I don't know how to convert the data into text in the ' ' without using an input and there's gotta be a better way. I can't find any info, all these people are entering hard values and it's like I need data already stored in other tables that's been retried. Any advice? Thanks.
0
Upvotes
3
u/martinbean Mar 20 '26
Data in the
$_POSTsuperglobal comes from form submissions. Why are you stick random variables in there? Show the problem code.3
u/JohnCasey3306 Mar 20 '26
Based on your description I think there's a misunderstanding. List out what you're currently trying to do.
3
u/Big-Dragonfly-3700 Mar 21 '26
it's possible to learn correct programming practices, without much additional effort, while learning the basics, so that you don't need to go back and redo your code multiple times to make it secure, proved a good User eXperience (UX), and have validation and error handling so that your code will either work or it will tell you when and why it doesn't work.
Here's a list of items for the code -
11
u/No_Astronomer9508 Mar 20 '26
You're overcomplicating this by trying to force variables into the
$_POSTarray.$_POST(and$_GET) are only meant for receiving data from the client (forms/URLs). If the data is already inside your PHP script as variables, you don't need to "post" them to yourself.Just pass your variables directly into your SQL query using prepared statements.
Here is the logic:
Table A->Fetch into PHP Variable->Insert into Table BExample:
PHP
You don't need to "post" to yourself. Just use the variables you have.
Select to get variable to php, Insert into or update for write it into another table. Greetings from a german guy with 16 Years of PHP/SQL knowledge.
1
u/Aggressive_Ad_5454 Mar 21 '26
$offer_id = $_POST[ ‘offer_amount’]
?? Doesn’t look quite right to me.