Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2017 10:25
Show Gist options
  • Select an option

  • Save anonymous/2c531455c046068f16142b0b7768781a to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2c531455c046068f16142b0b7768781a to your computer and use it in GitHub Desktop.
Polish My Skill - 30Mac || 1 Apr Upload file(morning session)
<!DOCTYPE html>
<html>
<head>
<html lang="en-US">
<meta charset="UTF-8">
<title>Polish Your Skills</title>
</head>
<body>
<h2>Example 1</h2>
<h3>Form Element</h3>
<h1>&lt;form id="myform" name="myform" method="POST" action=""&gt;</h1>
<h1>&lt;input id="mytextinput" name="mytextinput" value="NAMA"&gt;</h1>
<h1>&lt;/form&gt;</h1>
<hr>
<h3>Isi borang dibawah:</h3>
<p><form id="myform" name="myform" method="POST" action="">
<label>Nama :</label><input type="text" id="mynama" name="mynama" value="NAMA">
<label>No. KP :</label><input type="text" id="mynokp" name="mynokp" value="No. KP">
<input type="submit" id="mybutton" name="mybutton" value="Submit">
</form></p>
</body>
</html>
<?php
$product_id=$_GET['id'];
$conn=mysqli_connect('localhost','root','','mudah');
if (!$conn) {
die('Cannot connect to database');
}
$sql="DELETE FROM product WHERE id='$product_id'";
$result=mysqli_query($conn,$sql);
if ($result) {
echo 'Delete successful';
}
else {
echo 'Cannot delete table';
}
echo '<br /><a href="productlist.php">Back to Product List</a>';
?>
<!DOCTYPE html>
<html>
<?php
if ( !isset($_GET['id']) || empty($_GET['id']) ) {
echo 'Empty id';
}
?>
<?php
$conn=mysqli_connect('localhost','root','','mudah');
if (!$conn) {
die('Cannot connect to database');
}
echo 'Database connected...';
?>
<head>
<meta charset="UTF-8">
<title>Prodcuct Listing</title>
<style type="text/css">
#tblproduct {
border: solid 1px #ddd;
border-collapse: collapse;
width: 95%;
font-family: "Callibri", sans;
font-size: 14px;
text-align: center;
}
#tblproduct th {
border: solid 1px #ccc;
height: 42px;
background-color: #fff;
}
#tblproduct tr, #tblproduct td {
border: solid 1px #ccc;
height: 42px;
}
#tblproduct tr:nth-child(even) {
height: 48px;
color: #000;
background-color: #ddd;
}
#tblproduct tr:nth-child(odd) {
height: 48px;
color: #000;
background-color: #f4ffc6;
}
</style>
</head>
<body>
<?php
$passed_id=$_GET['id'];
$sql="SELECT * FROM product WHERE id='$passed_id'";
$res=mysqli_query($conn,$sql) or die('Cannot run query');
$row=mysqli_fetch_assoc($res);
?>
<h1>Product Edit</h1>
<form id="editform" name="editform" method="post" action="updateproduct.php">
<input type="hidden" name="product_id" value="<?php echo $row['id']; ?>">
<table id="tblproduct" name="tblproduct">
<tr>
<td>ID</td>
<td><?php echo $row['id']; ?></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" id="inpname" name="inpname" value="<?php echo $row['name']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><button type="submit">Update</button></td>
</tr>
</table>
</form>
<?php
mysqli_close($conn);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<html lang="en-US">
<meta charset="UTF-8">
<title>Polish Your Skills</title>
</head>
<body>
<h2>Example 1</h2>
<h1>Submit Form</h1>
<form id="form1" name="form1" method="post" action="saveformsubmit.php">
<input type="text" name="namasaya" id="inpnokp" value="">
<select name="inpselect">
<option value="" selected="selected">(Please Select)</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="checkbox" name="chkbox[]" value="1" />1
<input type="checkbox" name="chkbox[]" value="2" />2
<input type="checkbox" name="chkbox[]" value="3" />3
<input type="checkbox" name="chkbox[]" value="4" />4
<button type="submit">Submit</button>
</form>
<hr>
<a href="productlist.php">Product List</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<html lang="en-US">
<meta charset="UTF-8">
<title>Polish Your Skills</title>
</head>
<body>
<h2>Example 1</h2>
<h1>Submit Form</h1>
<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="saveform2.php">
<input type="text" name="inpnokp" id="inpnokp" value="">
<input type="file" name="inpfile" id="inpfile" accept="image/gif, image/jpeg" onchange="readURL(this);">
<button type="submit">Submit</button>
</form>
<br />
<img width="216" height="180" alt="selected-file" id="imgpreview" name="imgpreview" src="" />
</body>
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('imgpreview').src=e.target.result;
//$('#imgpreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Front Page</title>
<style>
#tbltitle, #tbldata {
font-family: "Callibri", arial, sans-serif;
font-size: 14px;
letter-spacing: 1px;
border-collapse: collapse;
width: 95%;
}
#tbltitle tr {
height: 45px;
font-size: 18px;
}
#tbldata td, #tbldata th {
border: 1px dashed #888;
text-align: left;
padding: 8px;
}
#tbldata tr:nth-child(even) {
height: 48px;
color: #000;
background-color: #ddd;
}
#tbldata tr:nth-child(odd) {
height: 48px;
color: #000;
background-color: #f4ffc6;
}
#tbldata tr.tr-head {
color: #fff;
background-color: #aaa;
}
</style>
</head>
<body>
<?php
$condb=mysqli_connect('localhost','root','','dbokms');
if (!($condb)) {
die('Could not connect to database'. mysqli_connect_error());
}
//echo '[==== Database connected ===]<br />';
?>
<table id="tbltitle" name="tbltitle" align="center">
<tr height="45">
<td>Product List</td>
<td align="right">[Add New Product]</td>
</table>
<table id="tbldata" name="tbldata" align="center">
<thead>
<tr class="tr-head">
<th width="3%">#</th>
<th>NEGARA</th>
<th>NEGERI</th>
<th>KOD</th>
<th>NAMA</th>
<th style="text-align:center">ACTION</th>
</tr>
</thead>
<tbody>
<?php
$sql="select * from code_bandar order by nama asc";
$res=mysqli_query($condb,$sql);
$num_rows=mysqli_num_rows($res);
$numbr=1;
if ($num_rows>0) {
while ($rows=mysqli_fetch_array($res)) {
?>
<tr>
<td><?php echo $numbr; ?>.</td>
<td><?php echo $rows['kodnegara']; ?></td>
<td><?php echo $rows['kodnegeri']; ?></td>
<td><?php echo $rows['kod']; ?></td>
<td><?php echo $rows['nama']; ?></td>
<td style="text-align:center">Edit&nbsp;|&nbsp;Delete</td>
</tr>
<?php
$numbr++;
} //end while
} //end if
else {
?>
<tr>
<td colspan="4"> --- NO RECORDS --- </td>
</tr>
<?php
} //end else
?>
</tbody>
</table>
<?php
mysqli_close($condb);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<?php
$conn=mysqli_connect('localhost','root','','mudah');
if (!$conn) {
die('Cannot connect to database');
}
echo 'Database connected...';
?>
<head>
<meta charset="UTF-8">
<title>Prodcuct Listing</title>
<style type="text/css">
#tblproduct {
border: solid 1px #ddd;
border-collapse: collapse;
width: 95%;
font-family: "Callibri", sans;
font-size: 14px;
text-align: center;
}
#tblproduct th {
border: solid 1px #ccc;
height: 42px;
background-color: #fff;
}
#tblproduct tr, #tblproduct td {
border: solid 1px #ccc;
height: 42px;
}
#tblproduct tr:nth-child(even) {
height: 48px;
color: #000;
background-color: #ddd;
}
#tblproduct tr:nth-child(odd) {
height: 48px;
color: #000;
background-color: #f4ffc6;
}
</style>
</head>
<body>
<h1>Product Listing</h1>
<table id="tblproduct" name="tblproduct">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM product WHERE name <> 'NAMA'";
$res=mysqli_query($conn,$sql) or die('Cannot run query');
$num_rows=mysqli_num_rows($res);
$numbr=1;
if ($num_rows>0) {
while ($row=mysqli_fetch_array($res)) {
?>
<tr>
<td><?php echo $numbr; ?></td>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><a href="editproduct.php?id=<?php echo $row['id']; ?>">Edit</a> | <a href="deleteproduct.php?id=<?php echo $row['id']; ?>">Delete</a></td>
</tr>
<?php
$numbr++;
}
// echo 'query return rows';
}
else {
echo 'Table empty';
}
?>
</tbody>
</table>
</body>
</html>
<?php
//mysql_connect( $dbHost, $dbUser, $dbPasswd ) or error( mysql_error() );
mysql_connect('localhost','root', '') or die( mysql_error() );
//mysql_select_db( $dbName );
mysql_select_db('mudah') or die( mysql_error() );
if ( isset($_POST['inpnokp']) && !empty($_POST['inpnokp']) ) {
echo $_POST['inpnokp'];
}
else {
echo 'Submit request error';
}
?>
<?php
//mysql_connect( $dbHost, $dbUser, $dbPasswd ) or error( mysql_error() );
mysql_connect('localhost','root', '') or die( mysql_error() );
//mysql_select_db( $dbName );
mysql_select_db('mudah') or die( mysql_error() );
if ( isset($_POST['inpnokp']) || empty($_POST['inpnokp']) ) {
echo $_POST['inpnokp'];
}
else {
echo 'Submit request error';
}
if(isset($_FILES['txtfile'])) {
$txtfile=trim($_FILES['txtfile']['name']);
$txttmpfile=($_FILES['txtfile']['tmp_name']);
if (!empty($txtfile)) {
$filename=str_replace(' ','_',$txtfile);
$fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$fdir='upload/'.$filename;
move_uploaded_file($txttmpfile,$fdir);
$fuplfile=$txtfile;
}
else {
$fdir='';
$fuplfile='';
}
}
else {
$fdir='';
$fuplfile='';
}
?>
<?php
if ( !isset($_POST['namasaya']) || empty($_POST['namasaya']) ) {
echo '<p style="font-size:32px;"> Please fill-in the input nama</p>';
}
else {
$namasaya=strtoupper(trim($_POST['namasaya']));
echo '<p style="font-size:32px;"> Your name is'.$_POST['namasaya'].'</p>';
}
if ( !isset($_POST['inpselect']) || empty($_POST['inpselect']) ) {
echo '<p style="font-size:32px;"> Please select option</p>';
}
else {
$select=$_POST['inpselect'];
echo '<p style="font-size:32px;"> Your selection is'.$_POST['inpselect'].'</p>';
}
if ( isset($_POST['chkbox']) ) {
if (is_array($_POST['chkbox'])) {
for($i=0; $i<count($_POST['chkbox']);$i++) {
echo 'Checkbox value => '.$_POST['chkbox'][$i];
}
}
else {
echo 'Checkbox value => '.$_POST['chkbox'];
}
}
//mysql_connect($namahost,$namauser,$password)
// mysql_connect('localhost','root','') or die('Cannot connect to database');
// mysql_select_db('mudah');
//mysqli_connect(namahost,namauser,password,database);
$conn=mysqli_connect('localhost','root','','mudah');
if (!$conn) {
die('Cannot connect to database'.mysqli_connect_error());
}
$sql="INSERT INTO product(name,description) VALUES ('$namasaya','$select')";
// mysql_query($sql) or die('Cannot insert database');
mysqli_query($conn,$sql);
echo 'succesfully insert...';
echo '<a href="eg1.php">Back to form</a>';
?>
<?php
$product_id=$_POST['product_id'];
if (!isset($_POST['inpname']) || empty($_POST['inpname']) ) {
die('Input empty');
}
$nama=$_POST['inpname'];
$conn=mysqli_connect('localhost','root','','mudah');
if (!$conn) {
die('Cannot connecct to database');
}
$desc='TEST';
$sql="UPDATE product SET name='$nama',description='$desc' WHERE id='$product_id'";
$result=mysqli_query($conn,$sql);
if ($result) {
echo 'Update successful';
}
else {
echo 'Cannot update table';
}
echo '<br /><a href="productlist.php">Back to Product List</a>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment