Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set("error_reporting",E_ALL & ~E_NOTICE);
- ini_set("display_errors",1);
- include_once $_SERVER['DOCUMENT_ROOT'] . "/flourish/toinclude.php";
- $connstr="ISOMTEACHING5\INFOSYS280";
- $mydb=new fDatabase("mssql", "Diamonds","mytest","",$connstr,61495);
- $formmode=1;
- $id;
- $name;
- $weight;
- $colour;
- $cut;
- if($_REQUEST["submitter"]=="Search"){
- $id=$_REQUEST["searchid"];
- if($_REQUEST["searchid"]!=null&&$_REQUEST["searchid"]!=""){
- $queryres=$mydb->query("Select name, weight, colour, cut from diamond where ID=%i;",$_REQUEST["searchid"]);
- if($queryres->countReturnedRows()==0){
- $onloaddo="alert('ID ".$_REQUEST['searchid']." not found!');";
- $id="";
- }else{
- $resultrow=$queryres->fetchRow();
- $name=$resultrow['name'];
- $weight=$resultrow['weight'];
- $colour=$resultrow['colour'];
- $cut=$resultrow['cut'];
- $formmode=2;
- }
- }
- }else if($_REQUEST["submitter"]=="Save"){
- $mydb->execute("update Diamond set ".
- "Name=%s,".
- "Weight=%i,".
- "Colour=%s,".
- "Cut=%s ".
- "where ID=%i;",
- $_REQUEST["name"],
- $_REQUEST["weight"],
- $_REQUEST["colour"],
- $_REQUEST["cut"],
- $_REQUEST["diamondid"]);
- $onloaddo="alert('Saved existing diamond ".$_REQUEST["shipid"]."');";
- $shipid="";
- }
- ?>
- <HTML>
- <head>
- <script>
- function loadfunction(){
- <?php echo $onloaddo;?>
- }
- function validateinteger(whichcontrol, controlname){
- var whatvalue=parseInt(whichcontrol.value);
- if(whichcontrol.value.length==0)
- return true;
- else if(isNaN(whatvalue))
- alert(controlname + " must be a number!");
- else
- return true;
- }
- function cancelbuttclick(){
- document.getElementById("diamondid").innerHTML="";
- Diamonds.name.value="";
- Diamonds.name.disabled=true;
- Diamonds.weight.value="";
- Diamonds.weight.disabled=true;
- Diamonds.colour.value="";
- Diamonds.colour.disabled=true;
- Diamonds.cut.value="";
- Diamonds.cut.disabled=true;
- Diamonds.submitter.item(0).disabled=false;
- Diamonds.searchid.value="";
- Diamonds.searchid.disabled=false;
- Diamonds.submitter.item(1).disabled=true;
- Diamonds.cancelbutt.disabled=true;
- }
- </script>
- <link rel="stylesheet" type="text/css" href="test1.css">
- </head>
- <body onload="loadfunction();">
- <form name="Diamonds" method="post" action="test1.php">
- <div id="search">
- <table>
- <h1>Dimonds</h1>
- <h2>Search</h2>
- <tr>
- <td align="right"> For Diamond ID:</td>
- <td><input type="text" name="searchid"
- value="<?php echo $id?>"
- <?php if($formmode==2) echo 'disabled';?> size="5"
- onblur="validateinteger(Diamonds.searchid,'search id')"/></td>
- <td><input type="submit" name="submitter" value="Search" <?php if($formmode==2) echo 'disabled'?>/> </td>
- </tr>
- </table>
- </div>
- <div id="data">
- <h1>Data Entry</h1>
- <table>
- <tr>
- <td align="right">Diamond ID:</td>
- <td><span id="diamondid"><?php echo $id;?></span>
- <input type="hidden" name="diamondid" value="<?php echo $id;?>"</td>
- </tr>
- <tr>
- <td align="right"> Name:</td>
- <td><input type="text" name="name" value="<?php echo $name?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
- </tr>
- <tr>
- <td align="right"> Weight:</td>
- <td><input type="text" name="weight" value="<?php echo $weight?>" onblur="validateinteger(Diamonds.weight,'weight')" <?php if($formmode==1) echo 'disabled';?> size="15" /></td>
- </tr>
- <tr>
- <td align="right"> Colour:</td>
- <td><input type="text" name="colour" value="<?php echo $colour?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
- </tr>
- <tr>
- <td align="right"> Cut:</td>
- <td><input type="text" name="cut" value="<?php echo $cut?>" <?php if($formmode==1) echo 'disabled';?> size="30" /></td>
- </tr>
- <tr>
- <td>
- <input type="submit" name="submitter" value="Save" onclick="return checksave();" <?php if($formmode==1) echo 'disabled';?>/>
- </td>
- <td>
- </td>
- <td align="right">
- <input type="button" name="cancelbutt" value="Cancel" onclick="cancelbuttclick();" <?php if($formmode==1) echo 'disabled';?>/>
- </td>
- </tr>
- </table>
- </div>
- </table>
- </form>
- </body>
- </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement