简体   繁体   English

PHP $ _POST数据未在页面之间传递

[英]PHP $_POST data not being passed between pages

I've been trying to make a simple html form that passes data to a php page, eventually for insertion into a sql database. 我一直在尝试制作一个简单的html表单,该表单将数据传递到php页面,最终插入到sql数据库中。 I've made forms successfully for but for some reason can't find what the data isn't getting passed in this instance. 我已经成功地创建了表单,但是由于某种原因找不到在这种情况下没有传递数据的内容。

Using var_dump($_POST), I see upon submission of the html form there is no data being transferred. 使用var_dump($ _ POST),我看到在提交html表单后没有任何数据正在传输。 I have tried var_dump both within and outside of a if(isset($_POST['submit'])) {}, both with no success. 我在if(isset($ set _ $ [POST_'submit'])){}内外都尝试了var_dump,但都没有成功。 I'm beginning to think it's possibly an issue with my php install or something along those lines? 我开始认为这可能与我的php安装或类似问题有关?

HTML FORM: HTML格式:

<form action="programinsert.php" method="POST">
<p>
<label for="program_title"> Program Title: </label>
<input name="program_title" type="text" id="program_title">
</p>
<input type="submit" value="Submit">
</form>

programinsert.php: programinsert.php:

<?php
session_start();
define('DB_NAME', 'rluh_website');
define('DB_USER', 'root');
define('DB_PASS', 'swang');
define('DB_HOST', 'localhost');
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
if(!$link) {
    die('Error: ' . mysqli_error($link));
}
$db_select = mysqli_select_db($link, DB_NAME);
if(!$db_select) {
    die('Cannot use ' . DB_NAME . ': ' . mysqli_error($link));
}
var_dump($_POST);
?>

Thanks for the replies everyone. 感谢大家的答复。 The issue in the end seemed to be when running the web pages (which are hosted locally) from the IDE I am using, PhpStorm. 最终的问题似乎是从我正在使用的IDE PhpStorm运行网页(本地托管)时。 PhpStorm opens up the pages under localhost:63342, rather than plain localhost. PhpStorm打开位于localhost:63342下的页面,而不是普通localhost。 Erasing these numbers let the data pass through as expected. 删除这些数字可使数据按预期方式通过。

I believe you need to GET what is being posted by the form. 我相信您需要获取表单发布的内容。

Here is a simplified plunk of the issue: https://embed.plnkr.co/uLnaPnHFtrmE6Dr6101F/ 这是该问题的简化示例: https ://embed.plnkr.co/uLnaPnHFtrmE6Dr6101F/

Are you sure database information is correct ? 您确定数据库信息正确吗? And try adding a "/" 并尝试添加“ /”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM