Hello everyone,
I’m a Newbie web app developer. Recently, I finished my project on Mamp
and trying to move everything into server. Then odd things happened. The $_POST
function all of sudden does not work.
I googled this question for two days and tried many things. Like
changing apache config, reinstall some php package. I tried to use .htaccess, but did not figure out how it works. I just wondering is there
any other way to make this thing works as i tested on mamp.
By the way,i use LAMP in server.
Here is php code. var_dump($_POST) will return null and
var_dump($_REQUEST) will return array{}.
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ID=$_POST['Client_ID'];
$name=$_POST['username'];
var_dump($_POST);
$sex=$_POST['sex'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$time=$_POST['time'];
$company_name=$_POST['Company_name'];
$wechat_id=$_POST['Wechat_id'];
if ($sex==0){
$sex="female";
} else {
$sex="male";
}
$delOrnot=0;
$sql="INSERT INTO Client(client_id,owner_name,gender,cell_phone,email,time,company_name,delOrnot,department) VALUES ('{$ID}','{$name}','{$sex}','{$mobile}','{$email}','{$time}','{$company_name}','{$delOrnot}','{$wechat_id}')";
if($conn->multi_query($sql)===TRUE){
echo"New records created successfully";
}else {
echo "Error " . $sql . "<br>" . $conn->error;
}
$conn->close();
Here is html code.
<form action="member-add.php" method="post" class="form form-horizontal" id="form-member-add">
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>userID:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text" value="" placeholder="" id="Client_ID" name="Client_ID">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>username:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text" value="" placeholder="" id="username" name="username">
</div>
</div>
</form>
And it works perfectly on mamp. I don’t know what is wrong on my server configurations. Thank you for your kindly help!
2
Answers
Is your php and HTML code is on same file?
I will suggest you to put your code at top of the file then check var_dump.
In your form opening tag
Try adding an enctype, this attribute specifies how the form-data should be encoded when submitting it to the server.
This is how it should look.
You can read more about the different enctypes HERE.
How to debug this
I think however that its more important to see, a possible way to debug this. When you make a request to the server, that request is sent and you can view, what you have sent to the server as well as the servers response. In order to do that (Chrome is used for this example), open your google developer tools (just press F12), then go to Networking and click on the request that its made when you click the send button.