Jump to content

[SOLVED] Help please!


psychowolvesbane

Recommended Posts

I have an order capture page that takes details from my Shopping Cart and creates a Sales Order containing these fields:

 

OrderID - int(6) - Primary

CampusID - varchar(10)

CollectionID - int(10)

OrderDate - date

TotalCost - decimal(5,2)

 

I have a script that first of all creates an entry in this table, OrderID and CollectionID are both supposed to be rand(111111,999999) and rand(1111111111,9999999999) respectively, however when the time comes for CollectionID to be added into the record it always ends up as 2147483647 regardless of all the attempts I've made at understanding why it is doing this.

 

The code for that part of my order_capture.php page is:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
session_start();
include "admin/connect_details.php";

if($_POST['CheckoutButton'] == "Checkout")
{
   $OrderID = rand(100000,999999); 
   
   $conn = mysql_connect($Host,$Username,$Password) or die(mysql_error());
   $db = mysql_select_db($Dbname, $conn);

   while($OkOrderID == false)
   {
      $sql1 = "SELECT OrderID FROM SalesOrder WHERE OrderID='$OrderID'";
      $rs1 = mysql_query($sql1,$conn) or die('Problem with query: ' . $sql1 . '<br />' . mysql_error());
    
      if(mysql_num_rows($rs1)==1)
      {
         $OkOrderID = false;
         $OrderID = rand(100000,999999);
      }
      else
      {
         $OkOrderID = true;
      }
   }

   $Campus = $_POST['Campus'];
   $TotalCost = $_POST['TotalCost'];
   
   $sql2 = "SELECT CampusID FROM Campus WHERE Campus='$Campus'";
   $rs2 = mysql_query($sql2,$conn) or die('Problem with query: ' . $sql2 . '<br />' . mysql_error());
   $row = mysql_fetch_array($rs2);
   
   $CampusID = $row['CampusID'];

   $CollectID = rand(1000000000,9999999999);
   
   while($OkCollectID == false)
   {
      $sql3 = "SELECT CollectionID FROM SalesOrder WHERE CollectionID='$CollectID'";
      $rs3 = mysql_query($sql3,$conn) or die('Problem with query: ' . $sql3 . '<br />' . mysql_error());
    
      if(mysql_num_rows($rs3)==0)
      {
         $OkCollectID = true;
         $CollectionID = $CollectID;
      }
      else
      {
         $OkCollectID = false;
         $CollectionID = rand(1000000000,9999999999);
      }
   }  

   echo "This is the CollectionID 1 (before query) ".$CollectionID."<br>";

   $OrderDate = date("Y/m/d");
   $UserID = $_SESSION['User_UserID'];

   $sqlAdd1 = "INSERT INTO SalesOrder (OrderID, CampusID, CollectionID, OrderDate, TotalCost) VALUES ('$OrderID', '$CampusID', '$CollectionID', '$OrderDate', '$TotalCost')";    
   $rsAdd1 = mysql_query($sqlAdd1,$conn);

   echo "This is the CollectionID 2 (after query) ".$CollectionID."<br>";

 

The strange things is that the echo of CollectionID before and after are exactly the same and are completely random, yet somehow the entry in the table is still 2147483647, and there are no other entries with that number, or entries it copies the number from.

 

Can anyone see where this phantom number is coming from? ??? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.