title: Script acting odd on Iphone
body: <p>first let me say that I have had no schooling in coding, I have taught myself everything from tutorials and such online so I know the code I include is going to be far from proper or ideal.</p>
  
  <p>I am working on building a simple inventory management program for my work. Basically there will be a QR code assigned to each item on the shelf that can be scanned to allow the user to either show how many have been used or to simply set the inventory to 0 so that more will be ordered.</p>
  
  <p>The problem I am running into is my script seems to work fine on my desktop but when I use my Iphone to scan the QR and deduct some items from inventory it will sometimes deduct double the amount selected in the dropdown. It doesn't happen every time so I am stumped.</p>
  
  <p>Here is the main script "Page-UpdateInventory.php":</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=200" /&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div align="center"&gt;
  &lt;?php
  $desiredid=$_GET["desiredid"];
  $action=$_GET["action"];
  $used=$_GET["used"];
  if (!$desiredid){
      include("Script-ClearVariables.php")
  ?&gt;
      &lt;form action="Page-UpdateInventory.php" method="get"&gt;
          What item would you like to update?
          &lt;br&gt;
          &lt;input type="text" name="desiredid" " size="15"&gt;
          &lt;br&gt;
          &lt;input type="Submit" value="Update Item"&gt;
      &lt;/form&gt;
  &lt;?
  }else{
      include ("Script-ConnectToDatabase.php");
      include ("Script-OneRecord.php");
      $db-&gt;close();
  }
  if ($process==1){
      echo "$item&lt;br&gt;&lt;br&gt;";
      if ($ordered==1){
          if (!$action){
              echo "&lt;form action='Page-UpdateInventory.php' method='get'&gt;";
              echo "&lt;input type='hidden' name='desiredid' value='$desiredid'&gt;&lt;input type='hidden' name='action' value='1'&gt;";
              echo "&lt;input type='Submit' value='Please Order More'&gt;&lt;/form&gt;";
          }else{
          include ("Script-ConnectToDatabase.php");
          include ("Script-ZeroOutStock.php");
          include ("Script-UpdateEntry.php");
          $db-&gt;close();
          echo "We will get that ordered ASAP";
          }
      }else{
          echo "An order has already been placed for this item";
      }
  }
  if ($process==2){
      echo "$item&lt;br&gt;&lt;br&gt;";
      if (!$action){
  ?&gt;
          &lt;form action="Page-UpdateInventory.php" method="get"&gt;
              &lt;input type="hidden" name="action" value="1"&gt;
              &lt;input type="hidden" name="desiredid" value="&lt;? echo "$desiredid"; ?&gt;"&gt;
              &lt;select name="used"&gt;
                  &lt;option value=1&gt;1&lt;/option&gt;
                  &lt;option value=2&gt;2&lt;/option&gt;
                  &lt;option value=3&gt;3&lt;/option&gt;
                  &lt;option value=4&gt;4&lt;/option&gt;
                  &lt;option value=5&gt;5&lt;/option&gt;
                  &lt;option value=6&gt;6&lt;/option&gt;
                  &lt;option value=7&gt;7&lt;/option&gt;
                  &lt;option value=8&gt;8&lt;/option&gt;
                  &lt;option value=9&gt;9&lt;/option&gt;
                  &lt;option value=10&gt;10&lt;/option&gt;
              &lt;/select&gt;
              &lt;br&gt;
              &lt;input type="Submit" value="I used some!"&gt;
          &lt;/form&gt;
  &lt;?  
      }else{
          include ("Script-ConnectToDatabase.php");
          include ("Script-ReduceStock.php");
          include ("Script-UpdateEntry.php");
          $db-&gt;close();       
          echo "Thank you for updating the inventory";
          if ($ordered==2){
              echo "&lt;br&gt;An order has been placed for this item";
          }   
      }
  }
  ?&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here are the scripts that are included:
  "Script-ClearVariables"
  This was one I added because I wondered if I was getting some carry over from a previous run. I don't think it made any difference:</p>
  
  <pre><code>&lt;?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;
  ?&gt;
  </code></pre>
  
  <p>"Script-ConnectToDatabase":</p>
  
  <pre><code>&lt;?php
  //CONNECT TO THE DATABASE
  $db = new mysqli('localhost', 'user', 'password', 'dbname');
  
  if($db-&gt;connect_errno &gt; 0){
      die('Unable to connect to database [' . $db-&gt;connect_error . ']');
  }
  ?&gt;
  </code></pre>
  
  <p>"Script-OneRecord":</p>
  
  <pre><code>&lt;?php
  //RETRIEVE A SINGLE DATABASE ROW BASED ON THE ITEM NUMBER PROVIDED IN THE URL AND LOAD THE RESULTS IN TO VARIABLES
  $sql = &lt;&lt;&lt;SQL
      SELECT *
      FROM `inventory`
      WHERE `id` = "$desiredid" 
  SQL;
  
  if(!$result = $db-&gt;query($sql)){
      die('There was an error running the query [' . $db-&gt;error . ']');
  }
  $row = $result-&gt;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-&gt;free();
  ?&gt;
  </code></pre>
  
  <p>"Script-ZeroOutStock"
  Another thing I tried. I thought maybe if I did the stock adjustments in seperate scripts it might help:</p>
  
  <pre><code>&lt;?php
  //SET THE CURRENT INVENTORY VARIABLE TO 0
  $current=0;
  ?&gt;
  </code></pre>
  
  <p>"Script-UpdateEntry":</p>
  
  <pre><code>&lt;?php
  //UPDATES AN EXISTING ENTRY
  $stmt = $db-&gt;prepare("UPDATE inventory SET property = ?,
  category = ?,
  item =?,
  minimum = ?,
  current = ?,
  store = ?,
  website = ?,
  part = ?,
  location = ?,
  instructions = ?,
  person = ?,
  process = ?,
  ordered = ?,
  misc1 = ?
  WHERE id = ?");
  $stmt-&gt;bind_param('sssiissssssiisi', 
  $property,
  $category,
  $item,
  $minimum,
  $current,
  $store,
  $website,
  $part,
  $location,
  $instructions,
  $person,
  $process,
  $ordered,
  $misc1,
  $id);
  $stmt-&gt;execute();
  $stmt-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>And lastly "Script-ReduceStock":</p>
  
  <pre><code>&lt;?php
  //REDUCE THE CURRENT INVENTORY BY WHATEVER IS IN THE $used VARIABLE
  $newcurrent=$current-$used;
  $current=$newcurrent;
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance for any advice you can give!</p>