0

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'];



}
?>
2
  • 3
    if you use a POST method to submit a form, then you must use $_POST to get the value. For example $invoiceid = $_POST['invoiceid'] Commented Mar 19, 2015 at 1:56
  • Also it is worth noting that inputting raw $_POST data to a database leaves you vulnerable to SQL injection, which could result in a database breach (or worse). Be sure to familiarize yourself with this article beforehand, so that you will know how to make your program more secure :) Commented Mar 19, 2015 at 2:52

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

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.