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



}
?>
Pushkar
  • 760
  • 15
  • 37
Anthony C.
  • 59
  • 3
  • 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'] – Christian Mar 19 '15 at 01: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](http://stackoverflow.com/questions/60174/) beforehand, so that you will know how to make your program more secure :) – pattyd Mar 19 '15 at 02:52

1 Answers1

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
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Sujan Shrestha
  • 612
  • 3
  • 13
  • 34