Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
0

Notice: Undefined index:

Engaged ,
Mar 31, 2013 Mar 31, 2013

i have this working fine on another site and have just replicated it but on this site it isnt working, can someone see what i am doing wrong?

i am having an  error come up on my success.php page when returning from a paypal payment..

Notice: Undefined index: OrderID in E:\Domains\b\website.com\user\htdocs\success.php on line 248

basically when the transaction is successful the return page is return.php, this page tells

<?php

session_start();

$colname_rsReturn = "-1";

if (isset($_SESSION['OrderID'])) {

  $colname_rsReturn = $_SESSION['OrderID'];

}

mysql_select_db($database_beau, $beau);

$query_rsReturn = sprintf("SELECT Fulfilled FROM beauSS13_orders WHERE beauSS13_orders.OrderID = %s", GetSQLValueString($colname_rsReturn, "int"));

$rsReturn = mysql_query($query_rsReturn, $beau) or die(mysql_error());

$row_rsReturn = mysql_fetch_assoc($rsReturn);

$totalRows_rsReturn = mysql_num_rows($rsReturn);

if ($row_rsReturn['Fulfilled'] == 1) {

  header ("Location: success.php");

} else header ("Location: failed-order.php");

?>

so the value of the order is 1 then it send to success.php to update the stock as follows

<?php

// *** Update the stock ***

$details_table = "beauSS13_orderdetails";

$ID_column = "OrderID";

$details_prodID = "ProductID";

$details_qty = "Quantity";

$XStock_TableName = "beauSS13_products";

$XStock_FieldName = "Stock";

$XStock_unID = "ProductID";

if (!session_id()) session_start();

if (isset($_SESSION["OrderID"])) {

  mysql_select_db($database_beau, $beau);

  $details_Source = "select * from " .  $details_table . " where " . $ID_column . " = " . $_SESSION["OrderID"];

  $detailsRS = mysql_query($details_Source, $beau) or die(mysql_error());

  $row_detailsRS = mysql_fetch_assoc($detailsRS);

  do {

    $XStock_qtySource = "select " . $XStock_FieldName . " from " .  $XStock_TableName . " where " . $XStock_unID . " = " . $row_detailsRS[$details_prodID] . "";

    $XStock_rsUpd = mysql_query($XStock_qtySource, $beau) or die(mysql_error());

    $row_XStock_rsUpd = mysql_fetch_assoc($XStock_rsUpd);

    if ($row_XStock_rsUpd[$XStock_FieldName] > 0) {

      $XStock_new = $row_XStock_rsUpd[$XStock_FieldName] - $row_detailsRS[$details_qty];

      if ($XStock_new < 0) $XStock_new = 0;

      $XStock_UpdSource = "update " . $XStock_TableName . " set " . $XStock_FieldName . " = " . $XStock_new . " where " . $XStock_unID . " = " . $row_detailsRS[$details_prodID] . "";

      $XStock_rsUpd = mysql_query($XStock_UpdSource, $beau) or die(mysql_error());

    }

  } while ($row_detailsRS = mysql_fetch_assoc($detailsRS));

  $XStock_rsUpd = null;

  $detailsRS = null;

  session_unregister("OrderID");

}

?>

but when i get to this page i am getting the error

Notice: Undefined index: OrderID in E:\Domains\b\website.com\user\htdocs\success.php on line 248

and the stock isnt getting updated

line 248 is <p>Order <?php echo $_SESSION['OrderID']; ?> Successful<br />

so this is telling me that the session isnt being carried accross?

TOPICS
Server side applications
893
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 31, 2013 Mar 31, 2013

It's not clear from your code where line 248 is, but the last line of the code you have posted here uses this:

session_unregister("OrderID");

This destroys $_SESSION['OrderID']. So, if line 248 comes after that code, it would explain why you're getting the undefined index notice.

By the way, session_unregister() is deprecated, and has been removed from PHP 5.4. You should use unset() instead:

unset($_SESSION['OrderID']);

Translate
LEGEND ,
Mar 31, 2013 Mar 31, 2013

It's not clear from your code where line 248 is, but the last line of the code you have posted here uses this:

session_unregister("OrderID");

This destroys $_SESSION['OrderID']. So, if line 248 comes after that code, it would explain why you're getting the undefined index notice.

By the way, session_unregister() is deprecated, and has been removed from PHP 5.4. You should use unset() instead:

unset($_SESSION['OrderID']);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 31, 2013 Mar 31, 2013

yes thanks for that, i have seen why the stock update wasnt working and hit a bit of a problem.

the way the product range is set up is different. the stock amount isnt coming from the beauSS13_products as there are sizes involved so i have a table for stock (beauSS13_Stock)which has the following columns

StockID

ProductID

SizeID

Stock

so i cant tell my statement to update productID here as ProductID may have 4 sizes and the statement i have above will update all the productIDs with that value...

so i dont know what to do.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 01, 2013 Apr 01, 2013

i sorted this by just adding the stock id to the cart information and sending this ID to the orderdetails table

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2013 Apr 01, 2013
LATEST

Glad you got it sorted.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines