Advertisement
Guest User

Untitled

a guest
May 13th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.44 KB | None | 0 0
  1. <?php
  2.  ini_set("error_reporting",E_ALL & ~E_NOTICE);
  3.  ini_set("display_errors",1);
  4.  
  5.  include_once $_SERVER['DOCUMENT_ROOT'] . "/flourish/toinclude.php";
  6.  $connstr="ISOMTEACHING5\INFOSYS280";
  7.  $mydb=new fDatabase("mssql", "Diamonds","mytest","",$connstr,61495);
  8.  
  9.  $formmode=1;
  10.  
  11.  $id;
  12.  $name;
  13.  $weight;
  14.  $colour;
  15.  $cut;
  16.  
  17.  if($_REQUEST["submitter"]=="Search"){
  18.     $id=$_REQUEST["searchid"];
  19.     if($_REQUEST["searchid"]!=null&&$_REQUEST["searchid"]!=""){
  20.         $queryres=$mydb->query("Select name, weight, colour, cut from diamond where ID=%i;",$_REQUEST["searchid"]);
  21.         if($queryres->countReturnedRows()==0){
  22.             $onloaddo="alert('ID ".$_REQUEST['searchid']." not found!');";
  23.             $id="";
  24.         }else{
  25.             $resultrow=$queryres->fetchRow();
  26.             $name=$resultrow['name'];
  27.             $weight=$resultrow['weight'];
  28.             $colour=$resultrow['colour'];
  29.             $cut=$resultrow['cut'];
  30.             $formmode=2;
  31.         }
  32.     }
  33.    
  34.  }else if($_REQUEST["submitter"]=="Save"){
  35.     $mydb->execute("update Diamond set ".
  36.             "Name=%s,".
  37.             "Weight=%i,".
  38.             "Colour=%s,".
  39.             "Cut=%s ".
  40.             "where ID=%i;",
  41.             $_REQUEST["name"],
  42.             $_REQUEST["weight"],
  43.             $_REQUEST["colour"],
  44.             $_REQUEST["cut"],
  45.             $_REQUEST["diamondid"]);
  46.     $onloaddo="alert('Saved existing diamond ".$_REQUEST["shipid"]."');";
  47.     $shipid="";
  48.  
  49.    
  50.  }
  51.  
  52.    
  53.  ?>
  54. <HTML>
  55.  <head>
  56.   <script>
  57.  
  58.   function loadfunction(){
  59.         <?php echo $onloaddo;?>
  60.        }
  61.  
  62.   function validateinteger(whichcontrol, controlname){
  63.       var whatvalue=parseInt(whichcontrol.value);
  64.    if(whichcontrol.value.length==0)
  65.      return true;
  66.    else if(isNaN(whatvalue))
  67.      alert(controlname + " must be a number!");
  68.  
  69.    else
  70.      return true;
  71.   }
  72.  
  73.   function cancelbuttclick(){
  74.       document.getElementById("diamondid").innerHTML="";
  75.       Diamonds.name.value="";
  76.       Diamonds.name.disabled=true;
  77.       Diamonds.weight.value="";
  78.       Diamonds.weight.disabled=true;
  79.       Diamonds.colour.value="";
  80.       Diamonds.colour.disabled=true;
  81.       Diamonds.cut.value="";
  82.       Diamonds.cut.disabled=true;
  83.       Diamonds.submitter.item(0).disabled=false;
  84.       Diamonds.searchid.value="";
  85.       Diamonds.searchid.disabled=false;
  86.       Diamonds.submitter.item(1).disabled=true;
  87.       Diamonds.cancelbutt.disabled=true;
  88.      
  89.   }
  90.   </script>
  91.  
  92.     <link rel="stylesheet" type="text/css" href="test1.css">
  93.  </head>
  94.  
  95.  
  96.  <body onload="loadfunction();">
  97.  <form name="Diamonds" method="post" action="test1.php">
  98.  
  99.  
  100.   <div id="search">
  101.     <table>
  102.     <h1>Dimonds</h1>
  103.     <h2>Search</h2>
  104.      <tr>
  105.      <td align="right">&nbsp;&nbsp;For Diamond ID:</td>
  106.      <td><input type="text" name="searchid"
  107.      value="<?php echo $id?>"
  108.      <?php if($formmode==2) echo 'disabled';?> size="5"
  109.      onblur="validateinteger(Diamonds.searchid,'search id')"/></td>
  110.      
  111.      <td><input type="submit" name="submitter" value="Search" <?php if($formmode==2) echo 'disabled'?>/> </td>
  112.      </tr>
  113.     </table>
  114.  </div>
  115.  
  116.  
  117.   <div id="data">
  118.     <h1>Data Entry</h1>
  119.     <table>
  120.      <tr>
  121.       <td align="right">Diamond ID:</td>
  122.       <td><span id="diamondid"><?php echo $id;?></span>
  123.       <input type="hidden" name="diamondid" value="<?php echo $id;?>"</td>
  124.      </tr>
  125.      
  126.      <tr>
  127.         <td align="right">&nbsp;&nbsp;Name:</td>
  128.         <td><input type="text" name="name" value="<?php echo $name?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
  129.      </tr>
  130.      
  131.       <tr>
  132.         <td align="right">&nbsp;&nbsp;Weight:</td>
  133.         <td><input type="text" name="weight"  value="<?php echo $weight?>" onblur="validateinteger(Diamonds.weight,'weight')" <?php if($formmode==1) echo 'disabled';?> size="15" /></td>
  134.      </tr>
  135.      
  136.      <tr>
  137.         <td align="right">&nbsp;&nbsp;Colour:</td>
  138.         <td><input type="text" name="colour"  value="<?php echo $colour?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
  139.      </tr>
  140.      
  141.       <tr>
  142.         <td align="right">&nbsp;&nbsp;Cut:</td>
  143.         <td><input type="text" name="cut" value="<?php echo $cut?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
  144.      </tr>
  145.      
  146.      <tr>
  147.      <td>
  148.        <input type="submit" name="submitter" value="Save" onclick="return checksave();" <?php if($formmode==1) echo 'disabled';?>/>
  149.      </td>
  150.      <td>
  151.      </td>
  152.       <td align="right">
  153.         <input type="button" name="cancelbutt" value="Cancel" onclick="cancelbuttclick();" <?php if($formmode==1) echo 'disabled';?>/>
  154.       </td>
  155.      </tr>
  156.  
  157.  
  158.     </table>
  159.   </div>
  160.    
  161.   </table>
  162.  </form>
  163.  </body>
  164.  
  165. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement