I'm new and hoping to learn programming. I chose PHP and working my way with 4th edition Oreilly. I'm trying to understand the first major program. I'm sure it is very simple but I don't quite understand one part. In the following parts of the program which i simplified a bit to the relevant bits:
$conn = new mysqli(parameters to connect to database)
$stuff = get_post($conn, 'stuff')
$query = "INSERT INTO table VALUES" . "('$stuff')"
$result = $conn->query(query)
Function get_post($conn, $var)
Return $conn->real_escape_string($_POST[$var])
I understand it's a way to prevent hacks with malicious user input. The part I don't understand is why or how the $_POST
which contains the form user input is treated as a property of the database before it goes in the database? (With the last line) I thought stuff would be stripped before going into a database. I'm sure I'm missing something very elementary here so I hope someone can explain how this works.
Basically I struggle to see how $_POST
becomes a property of $conn
. Can anyone walk me through it?
Thanks for any assistance.