简体   繁体   中英

Using php how can I update a row in mysql database based on a forms input value?

I have a form that has various inputs. One of the inputs contains a pre determined value that is loaded by script that is named "invoiceid". This invoiceid is the name and id of the form input and also the name of a column in my database. How can update the row in my database that contains the same value under the invoiceid column with all other form data submitted? I dont know what I'm doing...please help. Thanks for your time.

FORM

<form action="update.php" id="contactForm" method="post">

<input id="invoiceid" name="invoiceid" type="hidden" value=""/>

<input id="txt1" name="txt1" type="text" value=""/>

<input id="q1" name="q1" value="9.50" checked="checked" type="radio">
<input id="q1" name="q1" value="12.50" type="radio">

<select id="selectbox" name="selectbox">
<option selected="selected" value="">Please select...</option> 
 <option value="PURCHASE">Order for Purchase</option>
 <option value="REVIEW">Order for Review</option>
</select>

<button id="btn1" type="submit" name="submit">Submit</button></div>   

</form>

update.php

//Table name: seguin_orders

<?php

// Create the connection to the database
$con=mysqli_connect("xxx","xxx","xxx","xxx");


// Check if the connection failed
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  die();
}

   if (isset($_GET['invoiceid']))
{
    $invoiceid= $_GET['invoiceid'];



}
?>

I think it can help you.

update.php

<?php
   // Create the connection to the database
   $con=mysqli_connect("xxx","xxx","xxx","xxx");

  // Check if the connection failed
  if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    die();
   }

  if (isset($_POST['invoiceid']))
  {
   $invoiceid= $_POST['invoiceid'];
   $column1 = $_POST['txt1']; 
   $column2 = $_POST['q1'];
   $column3 = $_POST['selectbox'];
   $sql = "UPDATE TableName SET column1='".$column1."', column2='".$column2."', column3='".$column3."' WHERE invoiceid='".$invoiceid."'";
  }
?>

///note: change the table name and column names according to your database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM