I am trying to create a Python script that will fill some information in the database. For the server side I have used PHP and when I try to submit information using a browser, it works. But when I try to do it using the below Python script, it doesn't.
import requests url_insert = 'http://192.168.1.100/index.php' data_insert = {'fullname':'spiderman', 'ssn':'1234', 'dept':'Security', 'salary':10000, 'homeaddress':'New York', 'btn_save':'Save'} req = requests.post(url_insert, data = data_insert) print(req.text) Response:
Connected Successfully.<br><html> <head> <title>RETRIEVE DATA</title> </head> <body> <form action="data.php" method="POST"> <div class="form-group"> <label for="id">Full Name</label> <input type="text" name="fullname" id="fullname" value="" placeholder="FullName"> <br> <br> <label for="id">Social Security Number</label> <input type="text" name="ssn" id="ssn" value="" placeholder="Social Security Number"> <br> <br> <label for="id">Department</label> <input type="text" name="dept" id="dept" value="" placeholder="Department"> <br> <br> <label for="id">Salary</label> <input type="text" name="salary" id="salary" value="" placeholder="Salary"> <br> <br> <label for="id">Address</label> <input type="text" name="homeaddress" id="homeaddress" value="" placeholder="Address"> <br> <br> <input type="submit" name="btn_save" value="Save"> </div> </form> </body> </html> HTML CODE:
<html> <head> <title>RETRIEVE DATA</title> </head> <body> <form action="data.php" method="POST"> <div class="form-group"> <label for="id">Full Name</label> <input type="text" name="fullname" id="fullname" value="" placeholder="FullName"> <br> <br> <label for="id">Social Security Number</label> <input type="text" name="ssn" id="ssn" value="" placeholder="Social Security Number"> <br> <br> <label for="id">Department</label> <input type="text" name="dept" id="dept" value="" placeholder="Department"> <br> <br> <label for="id">Salary</label> <input type="text" name="salary" id="salary" value="" placeholder="Salary"> <br> <br> <label for="id">Address</label> <input type="text" name="homeaddress" id="homeaddress" value="" placeholder="Address"> <br> <br> <input type="submit" name="btn_save" value="Save"> </div> </form> </body> </html> I am new to this, and any help would be much appreciated.