listrecords.php
Code: Select all
<?php
$host="localhost"; // Host name
$username="left blank"; // Mysql username
$password="**********"; // Mysql password
$db_name="metrics"; // Database name
$tbl_name="***"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>Update your enteries: </strong> </td>
</tr>
<tr>
<td align="center"><strong>Date</strong></td>
<td align="center"><strong>User ID</strong></td>
<td align="center"><strong>Shift</strong></td>
<td align="center"><strong>Rotation Name</strong></td>
<td align="center"><strong>Rotation Complete</strong></td>
<td align="center"><strong>Total Tapes Required</strong></td>
<td align="center"><strong>Total Tapes Entered</strong></td>
<td align="center"><strong>Total Tapes Removed</strong</td>
<td align="center"><strong>Comments</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['date']; ?></td>
<td><? echo $rows['userid']; ?></td>
<td><? echo $rows['shift']; ?></td>
<td><? echo $rows['rotname']; ?></td>
<td><? echo $rows['rotationcomplete']; ?></td>
<td><? echo $rows['totaltapesreq']; ?></td>
<td><? echo $rows['totalentered']; ?></td>
<td><? echo $rows['totalremoved']; ?></td>
<td><? echo $rows['comments']; ?></td>
// link to update.php and send value of id
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
Code: Select all
<?php
$host="localhost"; // Host name
$username="left blank"; // Mysql username
$password="*********"; // Mysql password
$db_name="metrics"; // Database name
$tbl_name="***"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Date</strong></td>
<td align="center"><strong>User ID</strong></td>
<td align="center"><strong>Shift</strong></td>
<td align="center"><strong>Rotation Name</strong></td>
<td align="center"><strong>Rotation Complete</strong></td>
<td align="center"><strong>Total Tapes Required</strong></td>
<td align="center"><strong>Total Tapes Entered</strong></td>
<td align="center"><strong>Total Tapes Removed</strong</td>
<td align="center"><strong>Comments</strong></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="date" type="text" id="date" value="<? echo $rows['date']; ?>"></td>
<td align="center"><input name="userid" type="text" id="userid" value="<? echo $rows['userid']; ?>" size="15"></td>
<td><input name="shift" type="text" id="shift" value="<? echo $rows['shift']; ?>" size="15"></td>
<td><input name="rotname" type="text" id="date" vale"<? echo $rows['rotname']; ?>" size="15"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
Code: Select all
<?php
$host="localhost"; // Host name
$username="left blank"; // Mysql username
$password="*********"; // Mysql password
$db_name="metrics"; // Database name
$tbl_name="***"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE $tbl_name SET date='$date', userid='$userid', shift='$shift', rotname='$rotname', rotationcomplete='$rotationcomplete', totaltapesreq='$totaltapesreq', totalentered='$totalentered', totalremoved='$totalremoved', comments='$comments' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='listrecords.php'>View result</a>";
}
else {
echo "ERROR";
}
?>

