ajax - Why doesn't this simple PHP return a response? -
this first php program i've written. ajax requests alright , i'm getting status 200 ok not getting response.
<?php class employee{ private $fn; private $ln; private $dpt; private $id; } function newemployee(){ $employee = new employee(); $fn = $_post['firstname']; $ln = $_post['lastname']; $dpt = $_post['department']; $id = sprintf('%08d', $globals['$id']); $globals['$id'] = $globals['$id'] + 1; echo "first name: $employee\nlast name: $ln\ndepartment: $dpt\nid: $id"; $employee -> fn = $_post['firstname']; $employee -> ln = $_post['lastname']; $employee -> dpt = $_post['department']; $globals['$employeearray'][]= $employee; $globals['$numofemployees'] = $globals['$numofemployees'] + 1; $numemployees = $globals['$numofemployees']; echo "first name: $employee\nlast name: $ln\ndepartment: $dpt\nid: $id\nnumber of employees: $numemployees"; } if(isset($_post['submit'])) { newemployee(); } $employeearray = array(); $id = 0; $numofemployees = 0; ?>
your code breaks because of line:
echo "first name: $employee\nlast name: $ln\ndepartment: $dpt\nid: $id";
what's happening is, you're trying output $employee = new employee();
string when it's object. php breaks here , not want continue going through rest of code.
maybe wanted so?
echo "first name: $fn\nlast name: $ln\ndepartment: $dpt\nid: $id";
you'll want replace other call of $employee
in second echo @ bottom of function.
as macbooc correctly pointed out, you're not sending $_post['submit']
form, maybe change so?
if(isset($_post['submit']))
->
if(isset($_post))
wiki
Comments
Post a Comment