脚本在Iphone上表现奇怪

时间:2016-04-08 12:06:21

标签: php ios

首先让我说我在编码方面没有上过学,我已经从教程和在线等方面自学了所有内容,所以我知道我所包含的代码远非正确或理想。

我正在为我的工作建立一个简单的库存管理程序。基本上会有一个QR代码分配给货架上的每个项目,可以扫描,以便用户显示已使用的数量或简单地将库存设置为0,以便订购更多。

我遇到的问题是我的脚本似乎在我的桌面上工作正常但是当我使用我的Iphone扫描QR并从库存中扣除一些项目时,它有时会扣除在下拉列表中选择的数量的两倍。它不会每次都发生,所以我很难过。

这是主要的脚本“Page-UpdateInventory.php”:

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=200" />
  <title></title>
</head>
<body>
<div align="center">
<?php
$desiredid=$_GET["desiredid"];
$action=$_GET["action"];
$used=$_GET["used"];
if (!$desiredid){
    include("Script-ClearVariables.php")
?>
    <form action="Page-UpdateInventory.php" method="get">
        What item would you like to update?
        <br>
        <input type="text" name="desiredid" " size="15">
        <br>
        <input type="Submit" value="Update Item">
    </form>
<?
}else{
    include ("Script-ConnectToDatabase.php");
    include ("Script-OneRecord.php");
    $db->close();
}
if ($process==1){
    echo "$item<br><br>";
    if ($ordered==1){
        if (!$action){
            echo "<form action='Page-UpdateInventory.php' method='get'>";
            echo "<input type='hidden' name='desiredid' value='$desiredid'><input type='hidden' name='action' value='1'>";
            echo "<input type='Submit' value='Please Order More'></form>";
        }else{
        include ("Script-ConnectToDatabase.php");
        include ("Script-ZeroOutStock.php");
        include ("Script-UpdateEntry.php");
        $db->close();
        echo "We will get that ordered ASAP";
        }
    }else{
        echo "An order has already been placed for this item";
    }
}
if ($process==2){
    echo "$item<br><br>";
    if (!$action){
?>
        <form action="Page-UpdateInventory.php" method="get">
            <input type="hidden" name="action" value="1">
            <input type="hidden" name="desiredid" value="<? echo "$desiredid"; ?>">
            <select name="used">
                <option value=1>1</option>
                <option value=2>2</option>
                <option value=3>3</option>
                <option value=4>4</option>
                <option value=5>5</option>
                <option value=6>6</option>
                <option value=7>7</option>
                <option value=8>8</option>
                <option value=9>9</option>
                <option value=10>10</option>
            </select>
            <br>
            <input type="Submit" value="I used some!">
        </form>
<?  
    }else{
        include ("Script-ConnectToDatabase.php");
        include ("Script-ReduceStock.php");
        include ("Script-UpdateEntry.php");
        $db->close();       
        echo "Thank you for updating the inventory";
        if ($ordered==2){
            echo "<br>An order has been placed for this item";
        }   
    }
}
?>
</div>
</body>
</html>

以下是包含的脚本: “脚本的ClearVariables” 这是我添加的,因为我想知道我是否从前一次运行中获得了一些结转。我认为它没有任何区别:

<?php
//CLEAR ALL VARIABLES AND SET THEM TO 0
$property=0;
$category=0;
$item=0;
$minimum=0;
$current=0;
$store=0;
$website=0;
$part=0;
$location=0;
$instructions=0;
$person=0;
$process=0;
$ordered=0;
$misc1=0;
$used=0;
$desiredid=0;
$id=0;
$action=0;
$db=0;
$row=0;
$result=0;
$sql=0;
$stmt=0;
$newid=0;
$add=0;
$newcurrent=0;
?>

“脚本-ConnectToDatabase”:

<?php
//CONNECT TO THE DATABASE
$db = new mysqli('localhost', 'user', 'password', 'dbname');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
?>

“脚本-OneRecord”:

<?php
//RETRIEVE A SINGLE DATABASE ROW BASED ON THE ITEM NUMBER PROVIDED IN THE URL AND LOAD THE RESULTS IN TO VARIABLES
$sql = <<<SQL
    SELECT *
    FROM `inventory`
    WHERE `id` = "$desiredid" 
SQL;

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
$row = $result->fetch_assoc();
$id = $row['id'];
$property = $row['property'];
$category = $row['category'];
$item = $row['item'];
$minimum = $row['minimum'];
$current = $row['current'];
$store = $row['store'];
$website = $row['website'];
$part = $row['part'];
$location = $row['location'];
$instructions = $row['instructions'];
$person = $row['person'];
$process = $row['process'];
$ordered = $row['ordered'];
$misc1 = $row['misc1'];
$result->free();
?>

“脚本-ZeroOutStock” 我试过的另一件事。我想也许如果我在单独的脚本中进行库存调整可能会有所帮助:

<?php
//SET THE CURRENT INVENTORY VARIABLE TO 0
$current=0;
?>

“脚本-UpdateEntry”:

<?php
//UPDATES AN EXISTING ENTRY
$stmt = $db->prepare("UPDATE inventory SET property = ?,
category = ?,
item =?,
minimum = ?,
current = ?,
store = ?,
website = ?,
part = ?,
location = ?,
instructions = ?,
person = ?,
process = ?,
ordered = ?,
misc1 = ?
WHERE id = ?");
$stmt->bind_param('sssiissssssiisi', 
$property,
$category,
$item,
$minimum,
$current,
$store,
$website,
$part,
$location,
$instructions,
$person,
$process,
$ordered,
$misc1,
$id);
$stmt->execute();
$stmt->close();
?>

最后是“Script-ReduceStock”:

<?php
//REDUCE THE CURRENT INVENTORY BY WHATEVER IS IN THE $used VARIABLE
$newcurrent=$current-$used;
$current=$newcurrent;
?>

提前感谢您提供任何建议!

0 个答案:

没有答案