0

I have a php script on server side that collects data and inserts into MySQL database ;

$sql = "INSERT INTO tbl_marks (value) VALUES ('".$_GET["value"]."')";

I can add values from browser without issues as such ;

http://localhost/write.php?value=100

But I can't post from Python using requests ;

r = requests.post('https://localhost/write.php?', data = {'value':'100'})

There are no errors or warnings but I see that no entries are written to the table from Python. What am I doing wrong ?

5
  • print(r.status_code) check if your POST message was successful? Commented Sep 24, 2020 at 15:13
  • Have you debugged your POST object to see what the result was? Commented Sep 24, 2020 at 15:15
  • you're using https in your python code. was that a typo. Commented Sep 24, 2020 at 15:15
  • status_code returns "200". Yes http-https difference was a typo, sorry Commented Sep 24, 2020 at 15:21
  • I searched around and tried all the methods like mimicing a browser with header but still issue remains. Anyone encountered similar behavior ? At response of Python : >This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support. How can I resolve this issue ? Commented Sep 24, 2020 at 16:18

1 Answer 1

1

The PHP you submitted is looking at GET values (Directly from the user by the way. Look into SQL injection attacks), but your python is making a POST request. Try this instead:

r = requests.get('http://localhost/write.php', params={'value': '100'})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.