0

I have a php script which adds rows to a MySQL database, when I set variables in the script it works fine. As is the norm I want values to be entered via an html page. To test that I understood I could run my php script with arguments to simulate the $_POST values, similar to: http://www.website.com/php/insert_client3.php?nickname='Bob'&emailaddress='bob@yahoo'

The script beginning is:

<?php
print_r($_POST);
var_dump($_POST);
// check for required fields 
$nickname = $_POST['nickname'];
$emailaddress = $_POST['emailaddress'];

print_r and var_dump are returning empty arrays, is my approach wrong or syntax? I'm trying to build up html entry of data by starting with the database and working back Any help appreciated... Thanks

miken32
  • 42,008
  • 16
  • 111
  • 154
  • the URL's syntax is a GET request, not POST. At best, you can alway try REQUEST. – Funk Forty Niner Feb 22 '17 at 22:51
  • 1
    @Fred-ii- Where in the duplicate question does it explain that? This question is more specific than the generic problem with undefined variables. – Barmar Feb 22 '17 at 23:30
  • @Barmar then the answer below didn't answer the question; so no idea why that got upvoted. Plus, seeing no green tick next to the answer, obviously didn't solve this, unless the OP doesn't know what to do, or just took off. What am I not grasping with the question and the answer? Seems pretty obvious here. – Funk Forty Niner Feb 22 '17 at 23:32
  • If my answer helped solve your problem, please feel free to upvote and mark as accepted. See http://stackoverflow.com/help/someone-answers. Thanks! – miken32 Feb 24 '17 at 04:49

1 Answers1

1

You're looking for $_GET and not $_POST. Variables passed in the query string are sent with an HTTP GET request, whereas HTTP POST request data is not visible in the URL.

<?php
print_r($_GET);
var_dump($_GET);
// check for required fields 
$nickname = $_GET['nickname'];
$emailaddress = $_GET['emailaddress'];
miken32
  • 42,008
  • 16
  • 111
  • 154