0

simple and short.

PHP:

$test = $_REQUEST['test'];
$query = "UPDATE right1 SET right2 = '$test' WHERE right = rightprint";
mysqli_query($db, $query);

HTML:

<form class="input-group" action="site_is_here" method="post">
<input id="test" type="text" value="">
<input id="post" type="button" value="Submit">
</form>

Basically, I am trying to update a PHP database when a user submits information into the form, it should change the data in the database.

The problem is that I don't know how to assign the value of the input (once submitted) to the $test variable, it keeps telling me that this is undefined index or variable. (All database connections are working, dont worry about that)

  • 1
    **WARNING**: your code is vulnerable to [SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) attacks. To prevent such attacks you should use [prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and parameterized queries. – William Perron May 30 '18 at 22:53
  • Are you using the same script to display the form and perform the update? – Barmar May 30 '18 at 23:45

1 Answers1

0

change this:

<input id="test" type="text" value="">
<input id="post" type="button" value="Submit">

to this:

<input id="test" name="test" type="text" value="">
<input id="post" name="post" type="button" value="Submit">

then in your php, your variable should be

$test = $_POST['test'];//note $test could be anyname, just and example
samezedi
  • 621
  • 5
  • 15