Miletone

Rp0 / Rp1.000.000

Sunday, September 29, 2019

PHP : Add Data Entry

<html>

   <head>
      <title>Add Data Entry</title>
  <style>
a:link {
  color: green;
  background-color: transparent;
  text-decoration: none;
}

a:visited {
  color: pink;
  background-color: transparent;
  text-decoration: none;
}

a:hover {
  color: red;
  background-color: transparent;
  text-decoration: underline;
}

a:active {
  color: yellow;
  background-color: transparent;
  text-decoration: underline;
}
</style>
   </head>
   <body style="background-color:powderblue;">
 
   <table border = "1" align="center" method="post">
 <tr>
            <td>
         <p><b>Add Data Entry</b></p>
 </td>
 <form action="#" method="post">
         </tr>
 
 <tr>
            <td>
         <p> Category </p><input type = "text" name = "FCategory" value="Computer Components"/>
 </td>
         </tr>

         <tr>
            <td>
         <p> ID </p><input type = "text" name = "FID" >
 </td>
         </tr>
       
         <tr>
            <td>
         <p> Name </p><input type = "text" name = "FName" />
 </td>
         </tr>

 <tr>
            <td>
         <p> Description </p><textarea rows="4" cols="50" name = "FDescription"> </textarea>
 </td>
         </tr>

 <tr>
            <td>
         <p> Price </p><input type = "text" name = "FPrice" />
 </td>
         </tr>
       
         <tr>
            <td>
         <p> Picture </p><input type = "text" name = "FPicture" />
 </td>
         </tr>
 <!--<script type='text/javascript'>
 function preview_image(event)
{
 var reader = new FileReader();
 reader.onload = function()
 {
  var output = document.getElementById('output_image');
  output.src = reader.result;
 }
 reader.readAsDataURL(event.target.files[0]);
}
</script>
<style>

</style>
 <tr>
            <td>
         <input type = "file" accept='image/*' onchange="preview_image(event) name="image""/>  <img id="output_image" src="image" alt="Home" style="width:100;height:100px;" align="center"></a></img>
 </td>-->

 <tr>
            <td>
 <input type = "submit" name = "save" value = "Save" />
 <input type = "reset" name = "reset" value = "Reset" />
 <a href="dn.php">Back to Home</a>
 </td>
         </tr>
 <?php
include "connect.php";
if(isset($_POST['save'])){
$Category = $_POST['FCategory'];
$ID = $_POST['FID'];
$Name = $_POST['FName'];
$Description = $_POST['FDescription'];
$Price = $_POST['FPrice'];
$Picture = $_POST['FPicture'];
$sql = "insert into data (Category, ID, Name, Description, Price, Picture)";
$sql .= "values ('$Category', '$ID', '$Name', '$Description', '$Price', '$Picture')";
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error .".";
}
echo"Data Saved";
}
?>
      </table>
      </form>
   </body>
</html>
<html>

   <head>
      <title>Add Data Entry</title>
  <style>
a:link {
  color: green; 
  background-color: transparent; 
  text-decoration: none;
}

a:visited {
  color: pink;
  background-color: transparent;
  text-decoration: none;
}

a:hover {
  color: red;
  background-color: transparent;
  text-decoration: underline;
}

a:active {
  color: yellow;
  background-color: transparent;
  text-decoration: underline;
}
</style>
   </head>
   <body style="background-color:powderblue;">
   
   <table border = "1" align="center" method="post">
 <tr>
            <td>
         <p><b>Add Data Entry</b></p>
 </td>
 <form action="#" method="post">
         </tr>
  
 <tr>
            <td>
         <p> Category </p><input type = "text" name = "FCategory" value="Computer Components"/> 
 </td>
         </tr>
 
         <tr>
            <td>
         <p> ID </p><input type = "text" name = "FID" > 
 </td>
         </tr>
         
         <tr>
            <td>
         <p> Name </p><input type = "text" name = "FName" /> 
 </td>
         </tr>
 
 <tr>
            <td>
         <p> Description </p><textarea rows="4" cols="50" name = "FDescription"> </textarea> 
 </td>
         </tr>
 
 <tr>
            <td>
         <p> Price </p><input type = "text" name = "FPrice" /> 
 </td>
         </tr>
         
         <tr>
            <td>
         <p> Picture </p><input type = "text" name = "FPicture" /> 
 </td>
         </tr>
 <!--<script type='text/javascript'>
 function preview_image(event) 
{
 var reader = new FileReader();
 reader.onload = function()
 {
  var output = document.getElementById('output_image');
  output.src = reader.result;
 }
 reader.readAsDataURL(event.target.files[0]);
}
</script>
<style>
</style>
 <tr>
            <td>
         <input type = "file" accept='image/*' onchange="preview_image(event) name="image""/>  <img id="output_image" src="image" alt="Home" style="width:100;height:100px;" align="center"></a></img>
 </td>-->

 <tr>
            <td>
 <input type = "submit" name = "save" value = "Save" />
 <input type = "reset" name = "reset" value = "Reset" />
 <a href="dn.php">Back to Home</a>
 </td>
         </tr>
 <?php
include "connect.php";  
if(isset($_POST['save'])){
$Category = $_POST['FCategory'];
$ID = $_POST['FID'];
$Name = $_POST['FName'];
$Description = $_POST['FDescription'];
$Price = $_POST['FPrice'];
$Picture = $_POST['FPicture'];
$sql = "insert into data (Category, ID, Name, Description, Price, Picture)";
$sql .= "values ('$Category', '$ID', '$Name', '$Description', '$Price', '$Picture')";
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error .".";
}
echo"Data Saved";
}
?>
      </table>
      </form>
   </body>
</html>

No comments: