将输入值输入php变量

Is there any method to take value of the input to a php variable.

<input type="text" name="s_amount" style='width:20%;' required>

I want value of this s_amount to take into a php variable $s_amount. This code is already inside a form. I want this conversion happen before submitting the form.

You can't convert a javascript variable into a php variable without communication with the server. So if you would like to turn a client side variable (your input value) into a php variable BEFORE submitting a form you'll need to post/get this variable to the server in a separate request. The best way to do this is by an asynchronous ajax call. If you are using jquery this can be very simple:

$.ajax({
    url: '/path/to/file.php',
    type: 'POST',
    dataType: 'text',
    data: {param1: $("input[type='text'][name='s_amount']").val()},
})
.done(function(response) {
    console.log("response");
    //do something with the response
})
.fail(function() {
    console.log("error");
})
.always(function() {
    console.log("complete");
});

On the server you can receive this value by getting the posted data like so

$myphpvariable= $_POST['param1'];
//here you can manipulate/validate your variable and echo something back to the client
echo 'this is my php variable: '.$myphpvariable;

Now your ajax call will receive "this is my php variable: [x]" in its .done() callback.

EDIT: don't forget you have a javascript console in your browser (for example firebug). this can be very handy to see what's going on.

PHP runs on the server. So in order to get the value to the script, you either have to use AJAX or you have to submit the form.

Change the HTML markup to:

<form method='POST'>
   <input type="text" name="s_amount" style='width:20%;' required>
   <input type="submit" name="submit" value="Submit" />
</form>

Then, submit the form, and after that you can extract the $_POST variable, but note that it will create variables for each key in that variable.

extract($_POST);
echo $s_amount;

Otherwise, you can submit the form, and simply do:

$s_amount = $_POST['s_amount'];

Just submit the form and get it using $_REQUEST/$_GET/$_POST.

HTML:

<form method="POST">
   <input type="text" name="s_amount" style="width:20%;" required>
   <input type="submit" name="submit" value="Submit" />
</form>

PHP:

<?php
   ...
   $value_in_php_var = $_POST['s_amount'];
   ...

This is for form

<form action="process.php" method="POST">
    <input type="text" id="table_name" name="table_name" placeholder="name" />
    <input type="submit" name="create_table" id="create_table" value="create a table"/>
</form>

This is in process.php

<?

$table_name = $_POST['table_name'];
// sql to create table
$sql = "CREATE TABLE $table_name (
        ID int AUTO_INCREMENT,
        date varchar(255),
        name varchar(255),
        organization varchar(255),
        email varchar(255),
        phone varchar(225),
        location varchar(225),
        respond varchar(225),
        created_by varchar(225),
        PRIMARY KEY (ID)
)";

if (mysqli_query($con, $sql)) {
    echo "Table $table_name created successfully";
} else {
    echo "Error creating table: " . mysqli_error($con);
}

mysqli_close($con);
?>