I can't really use PHP and from what I've seen in tutorials this should work, but it doesn't:
<html>
<head></head>
<body>
<form>
<input type='text' name="name" value='myName'>
</form>
<p>
<?php
$name = $_POST['name'];
echo $name
?>
</p>
</body>
</html>
Is there a reason I can't get the value of name? Sorry for asking such a simple question...
here is the fiddle http://jsfiddle.net/DCmu5/1/, so, please try what you said and send it to me only when it works before answering
try this
Well, you have to POST your form to get the value of
$_POST
variables. Add this to your<form>
Click button and whatever is typed in your field will show up.
PHP is a server-side language, so you'll need to submit the form in order to access its variables.
Since you didn't specify a
method
,GET
is assumed, so you'll need the$_GET
super-global:It's probably better though, to use
$_POST
(since it'll avoid the values being passed in the URL directly. As such, you can addmethod
attribute to your<form>
element as follows:Notice I also added a submit button for good measure, but this isn't required. Simply hitting return inside the textbox would submit the form.