0

I am getting an undefined variable when I submit a form. It successfully prints out the information using an echo but not outside the get function. I need it to get the previous product ID's, which the get function does. Then I need it to insert into the sql query, that is not working. I'm afraid its a bracket error. Here are snippets of my code:

     if (isset($_GET['productID'])) {

        $productID = ($_GET['productID']); 

    echo $productID;  //echos successfully
    }

// Doesn't echo here


    $query = "INSERT INTO orders (productID) VALUES ('$productID' )";       
        $results = @mysqli_query ($conn, $query);

?>


<form class="form-horizontal" role="form" method="post" action="checkout.php">

<div class="form-group">






            <div class="form-group">





<div class="form-group">
        <div class="col-sm-12 col-sm-offset-2">
    <input type="submit" name="submit" value="Submit" class="btn btn-default"/>
    </div>
    </div>

</form>


</div>




<?php
include ('footer.php');
?>
magic
  • 3
  • 2
  • your code doesn't hold water. You have PHP then HTML and not closing off the php for it. – Funk Forty Niner Apr 04 '17 at 18:24
  • @Fred-ii- notice I said snippets of code. It is closed off, I'm merely showing the parts of the code that aren't communicating with each other. – magic Apr 04 '17 at 18:26
  • well, you'd be surprised at what people post and others posting answers based on what was "seen". I know this all too well. – Funk Forty Niner Apr 04 '17 at 18:26

1 Answers1

0

Where is it named in your form?? When you load your page, the $_GET comes through but once you submit that page, that get variable gets lost because it is no longer within your form/page in the set of $_POST variables being submitted. Store it as a hidden input type for submission.

<input type='hidden' name='productid' value='<?php echo $productid;?>' />

Then, on submit

if(isset($_POST['submit'[)){
$productid = $_POST['productid'];
.
.
.
}
clearshot66
  • 2,292
  • 1
  • 8
  • 17