psychowolvesbane Posted April 23, 2008 Share Posted April 23, 2008 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 https://forums.phpfreaks.com/topic/102485-solved-help-please/ Share on other sites More sharing options...
davey_b_ Posted April 23, 2008 Share Posted April 23, 2008 2147483647 is PHP's max integer value... but i'm not an expert with your problem. Sorry! You could try $CollectID = rand(1000000000,2147483646); Link to comment https://forums.phpfreaks.com/topic/102485-solved-help-please/#findComment-524850 Share on other sites More sharing options...
psychowolvesbane Posted April 23, 2008 Author Share Posted April 23, 2008 Yes I understand now about 231-1 being the largest possible integer number, so I just decided to change the max to 9 digits instead of 10 as there is no specific requirement for it. Link to comment https://forums.phpfreaks.com/topic/102485-solved-help-please/#findComment-525102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.