0

I've been trying to make a simple html form that passes data to a php page, eventually for insertion into a sql database. 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. I have tried var_dump both within and outside of a if(isset($_POST['submit'])) {}, both with no success. I'm beginning to think it's possibly an issue with my php install or something along those lines?

HTML FORM:

<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:

<?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);
?>
  • looks like it should work, is this on localhost? php is running on a web-server? the url after form submission is: http://..../programinsert.php ? –  Apr 03 '18 at 23:01
  • Make sure you do not have a redirect happening – John Conde Apr 03 '18 at 23:03
  • var_dump($_REQUEST); what is the result ? – Jehad Ahmad Jaghoub Apr 03 '18 at 23:07
  • https://stackoverflow.com/questions/9002424/php-post-not-working – Gjermund Dahl Apr 03 '18 at 23:14
  • Errrrmmm `if(isset($_POST['submit'])) {}` there is no `name` property on the submit button, so there will be no `$_POST['submit']` in the post array. So amend to `` – RiggsFolly Apr 03 '18 at 23:21
  • Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. – RiggsFolly Apr 03 '18 at 23:21
  • All good advice. I did try your code (with all the database stuff commented out), and it does produce: "array(1) { ["program_title"]=> string(15) "this is a title" }" and if you follow Riggs on the submit, that shows up as well. – wordragon Apr 04 '18 at 02:16

3 Answers3

0

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. PhpStorm opens up the pages under localhost:63342, rather than plain localhost. Erasing these numbers let the data pass through as expected.

-1

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/

mckenro
  • 16
  • 5
  • post should work just fine, change the action is not a solution to the posted question –  Apr 04 '18 at 00:06
  • Poorly worded on my part. I was more trying to point out that there is nowhere in the php file that is gathering the value from the form. – mckenro Apr 04 '18 at 15:33
-1

Are you sure database information is correct ? And try adding a "/"