Hi all, I have this code that seems to work fine for the order but cant get it to pass the invoice side of things. the trouble im having is when i do the order its fine, but when i do an invoice it sends me back to the order creating form for some reason. Help please! New Ajax learner!


This is the ajax script:

<script type="text/javascript">
function showitem(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
   var OrderID =  document.getElementById("orderID");
   var QuoteID =  document.getElementById("quoteID");
   var InvoiceID =  document.getElementById("invoiceID");
	}
  }
xmlhttp.open("GET","/items/getitem.php?orderID=OrderID&quoteID=QuoteID&invoiceID=InvoiceID&q="+str,true);
xmlhttp.send();
}
</script>

This is the form that is on the order / quote / invoice creating page in php, the id is changed on the respective pages, the invoice page is where im having trouble, its fine when its orderID

echo "<div class='box'> 
<form>
Search for an Item:
<input type='hidden' id='invoiceID' value='$invoiceID'><input type='text' value='' onkeyup='showitem(this.value)'>
</form>
<br />
<div id='txtHint'></div></div>";

This is the item add to page which isn't seen as it is the processing page for items:

<?php
include("../config.php");
connect();
$submit = $_REQUEST['submit'];
$view = $_REQUEST['view'];
$quoteID = $_REQUEST['quoteID'];
$orderID = $_REQUEST['orderID'];
$invoiceID = $_REQUEST['invoiceID'];
$itemID = $_REQUEST['itemID'];
$item_code =$_REQUEST['item_code'];
$description = $_REQUEST['description'];
$list_exc = $_REQUEST['list_exc'];
$trade_exc = $_REQUEST['trade_exc'];
$rrp_exc = $_REQUEST['rrp_exc'];
$quantity = $_REQUEST['quantity'];
$total_exc = $quantity * $rrp_exc;

if($submit=="Add")
{
if(!$quoteID=="")
{
$table = "qItems";
$docID = "quoteID";
$dir = "quotes";
$reloID = "$quoteID";
}
if(!$invoiceID=="")
{
$table = "iItems";
$docID = "invoiceID";
$dir = "invoices";
$reloID = "$invoiceID";
}
if(!$orderID=="")
{
$table = "oItems";
$docID = "orderID";
$dir = "orders";
$reloID = "$orderID";
}
mysql_query("INSERT INTO `$table` (`$docID`, `itemID`, `item_code`, `description`, `list_exc`, `trade_exc`, `rrp_exc`, `quantity`, `total_exc`) 
VALUES ('$reloID', '$itemID', '$item_code', '$description', '$list_exc', '$trade_exc', '$rrp_exc', '$quantity', '$total_exc')");
}
if($submit=="Delete")
{
if(!$quoteID=="")
{
$table = "qItems";
$docID = "quoteID";
$dir = "quotes";
$reloID = "$quoteID";
}
if(!$invoiceID=="")
{
$table = "iItems";
$docID = "invoiceID";
$dir = "invoices";
$reloID = "$invoiceID";
}
if(!$orderID=="")
{
$table = "oItems";
$docID = "orderID";
$dir = "orders";
$reloID = "$orderID";
}
$quantity = $_REQUEST['quantity'];
mysql_query("DELETE FROM `$table` WHERE `$docID` = '$reloID' AND `itemID` = '$itemID' and `quantity` = '$quantity'");
}
header("location: ../$dir/vied.php?view=Update&$docID=$reloID");

?>

and this is the get item page that the ajax is calling:

<?php
include("../config.php");
$q = $_GET['q'];
$invoiceID = $_GET['invoiceID'];
$quoteID = $_GET['quoteID'];
$orderID = $_GET['orderID'];
connect();
$result = mysql_query("SELECT * FROM items WHERE description LIKE '%$q%'");

while($row = mysql_fetch_array($result))
 { 
  echo "
<form method='post' action='/items/addTo.php'>
<input type='hidden' name='quoteID' value='$quoteID'>
<input type='hidden' name='orderID' value='$orderID'>  
<input type='hidden' name='invoiceID' value='$invoiceID'>
<input type='hidden' name='itemID' value='".$row['itemID']."'>
<input type='hidden' name='list_exc' id='list' value='".$row['list_exc']."'>
<input type='hidden' name='trade_exc' value='".$row['trade_exc']."'>
<input type='hidden' name='item_code' value='" . $row['item_code'] . "'>
<input type='hidden' name='description' value='" . $row['description'] . "'>";
  echo $row['description'];
  echo " | ".$row['item_code'];
  echo " | $".$row['list_exc'];
  echo "
  <br /><input type='text' title='Retail price' name='rrp_exc' id='rrp' size='6' value='" . $row['rrp_exc'] . "'>";
  echo "<input type='text' title='Quantity' name='quantity' size='2' value='" . $row['quantity'] . "'>";
  echo "<input type='submit' name='submit' value='Add'></form>";
}
?>

Recommended Answers

All 2 Replies

In the PHP code addTo.php i noticed that is assumed that only one of this 3
posted paremeters is !="" to work:
$quoteID
$invoiceID
$orderID

Hare you sure this is verified?
Try to see if in the html page generated from getitem.php this condition is verified
controlling hidden paramaters:

<input type='hidden' name='quoteID' value='$quoteID'>
<input type='hidden' name='orderID' value='$orderID'>
<input type='hidden' name='invoiceID' value='$invoiceID'>

Only one of this paramaters MUST have a value

oh hey all yes i managed to sort it by setting the create page to a session which solved it. for others needing help, I found that I could set the variable as a session then call it on the getitem page. I added these lines to these files:

The item add to page, positioned at line 17 :

// store session data
$_SESSION['doctype']=invoice;
$_SESSION['id']=$invoiceID;

and of course start the session at the top of the said page.

Then this on the get item page positioned at line 8, same again with session start too:

session_start();
$doctype = $_SESSION['doctype'];
$docID = $_SESSION['id'];
$DOC = $doctype."ID";

and this as a hidden field in the same page:

<input type='hidden' name='$DOC' value='$docID'>

All sorted. Handy hint: Use sessions to pass an idea if you cant pass the variable, then call it on the page you want to use it with, simple as.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.