0

I am trying to do a simple comment box in my webpage, and followed an online tutorial to make one. I followed the instructions exactly, but mine doesn't work. This is the code that I have:

<?php 
if(isset($_POST['submit'])) {
    $fullname = $_POST['fullname'];
    echo $fullname;
}
?>

<html>
<head>
<title>Undefined Index Example</title>
</head>
<body>
<div style="margin: 100px auto 0;width: 300px;">
<h3>HTML Form</h3>
<form name="form1" id="form1" action="" method="post">
    <fieldset>
        Enter Full Name <input type="text" name="fullname" placeholder="Full Name" />
        <br />
        <input type="submit" name="submit" value="Submit" />
    </fieldset>
</form>
</div>
</body>
</html>

The problem seems like the name of the input type is not linked with my php part. For example, the php submit is not linked to the html submit, so it does nothing. I have no idea how to fix this, and is very frustrating. Please help.

Moon
  • 23
  • 2
  • 2
    and how are you using this as? on a webserver `http://localhost/file.php` or on your own PC? `file:///file.php` - 2 different animals here. I can't see how this would be failing. – Funk Forty Niner Mar 18 '16 at 16:20
  • *Beat me to it Ralph!* @Fred-ii- – Jay Blanchard Mar 18 '16 at 16:21
  • *Seemed to be the most likely scenario here Sam* - @JayBlanchard – Funk Forty Niner Mar 18 '16 at 16:21
  • basic debugging: `var_dump($_POST, $_SERVER['REQUEST_METHOD']);` and see what you get. – Marc B Mar 18 '16 at 16:21
  • I am not familiar with servers. currently I have a sqlite database set up, but do I need to be using a database for this? – Moon Mar 18 '16 at 16:23
  • Don't worry about a database until you setup a webserver. – Jay Blanchard Mar 18 '16 at 16:25
  • @Moon: This has nothing to do with a database. They're talking about a *web server*. Such as Apache or IIS or something like that. If you're just opening the file directly then there's nothing which is actually going to process the PHP code. PHP needs to be served from a web server and that server will process the PHP code before sending the *result* of that code to the browser. – David Mar 18 '16 at 16:26
  • @Fred-ii- I don't quite understand what you mean. I don't have any webservers set up and I am running this on my own PC. – Moon Mar 18 '16 at 16:27
  • @Moon: You're probably going to want to start with a PHP tutorial which shows you how to install PHP and get it set up and running before you start writing any PHP code. – David Mar 18 '16 at 16:27
  • Seems I was right in my first comment. – Funk Forty Niner Mar 18 '16 at 16:32
  • @David I do have php installed, and I also have xampp installed. I have other php codes that work. but I am not complete sure, so I want to test if I do have everything set up. Is there a good way to check that? – Moon Mar 18 '16 at 16:32
  • 1
    @Moon: The very first comment on this question is a good start. You can also look at the page source in your browser. If there's PHP code there, then the code is never being processed. (Web server or otherwise.) – David Mar 18 '16 at 16:34
  • Did you put this code in the web root of your XAMPP server? Typically `C:\xampp\htdocs` Is the XAMPP server running? – Jay Blanchard Mar 18 '16 at 16:36
  • @David I checked the page source in my browser, and php code wasn't there. – Moon Mar 18 '16 at 16:43
  • @Moon: Then you're going to have to do some debugging. Which could be as simple as some well-placed `echo` statements to see what's going on in the server-side code after it executes. – David Mar 18 '16 at 16:44
  • @JayBlanchard No, and you mean the index.php in c:\xampp\htdocs folder right? Also I didn't have xampp server running – Moon Mar 18 '16 at 16:45
  • There is your problem. – Jay Blanchard Mar 18 '16 at 16:48
  • @JayBlanchard I'm still confused, I have my apache running, and put my files in htdocs, but still has the same problem. – Moon Mar 18 '16 at 16:56
  • When you view the source of the page what do you see? – Jay Blanchard Mar 18 '16 at 16:57
  • @JayBlanchard I see everything that was written in html. – Moon Mar 18 '16 at 17:05
  • What if you click submit? Do you see anything different? – Jay Blanchard Mar 18 '16 at 17:10
  • Apparently there is something wrong with PHPStorm, it works if I use localhost from xampp, but if I use the phpstorm host, it does not work. – Moon Mar 20 '16 at 21:56

0 Answers0