-3

I would like click on submit and the value input in the field to be stored in database.

However, I do not want to use a form action. Is it possible to do it without creating form action with PHP?

<tr>
<form method="post">
<tr>
<td>
    <label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
    <input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
    <input type="submit" value="Save" id="submit" />
</td>
</tr>

<?php
if(isset($_POST['submit']))
{
var_dump($_POST); exit;

$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
  • Sidenote: You realize that everything inside `if(isset($_POST['submit'])){...}` will never fire up. – Funk Forty Niner Jan 18 '16 at 13:55
  • 1
    Yes, it is possible and quite a few ways actually. Depends on what else you don't want to use, such as jQuery/Ajax etc. question's a bit unclear. – Funk Forty Niner Jan 18 '16 at 13:58
  • Actually you will *always* have a method. A form without a method defaults to "GET". What are you trying to accomplish? – Jay Blanchard Jan 18 '16 at 14:03
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Jan 18 '16 at 14:04
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 18 '16 at 14:04
  • *See you on the wild side Sam* - @JayBlanchard – Funk Forty Niner Jan 18 '16 at 14:08
  • and OP, you'll notice a vote to close as unclear; that's mine. – Funk Forty Niner Jan 18 '16 at 14:08

1 Answers1

0

However, I do not want to use a form action. Is it possible to do it without creating form action with PHP?

No, that's not possible.

Just do it like this:

<tr>
<form method="post" action="mypage.php">
<tr>
<td>
    <label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
    <input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
    <input type="submit" value="Save" id="submit" />
</td>
</tr>
</form>

<?php
if(isset($_POST['finish_product']))
{
var_dump($_POST); exit;

$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
Tewdyn
  • 687
  • 3
  • 16