1

I was wondering if it was possible to take HTML user input using PHP (preferably the ID or something I can use numbers in) and to save confusion just echo it back.

So I have some example code here:

<input type="number" maxlength="3" name="test" id="1">
<input type="number" maxlength="3" name="test" id="2">
<input type="number" maxlength="3" name="test" id="2">

What I was looking for is a way where I could use their input and well.... echo it back for now.

2 Answers 2

2

if you already know how to submit a form you can use php on the other side like this to echo it out

<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>

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

in your example all three inputs are named "test" so youll need a different name for each one. My example above uses the "name" of the input to capture it. If your using "GET" change my $_POST['name'] to $_GET['name']

Sign up to request clarification or add additional context in comments.

Comments

1

Which method did you use for these inputs? Name them differently, then retrieve the data with:

 <?php echo $_GET['test1']; ?>
 <?php echo $_GET['test2']; ?> 
 <?php echo $_GET['test3']; ?>  

If you used POST type in the input method, then switch for:

<?php echo $_POST['test1']; ?> 
<?php echo $_POST['test2']; ?>
<?php echo $_post['test3']; ?> 

1 Comment

Well, the thing is I'm open to using any type of method to submit it to PHP. But I wanted to be able to have the PHP on the same page so I can echo on the same page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.