Re: PHP Search and edit functions
Posted: Fri Apr 09, 2010 5:24 pm
oh was looking at it as a whole. Not those tiny parts. Will look at it shortly
Code: Select all
<?php
// Connect to server and select database.
mysql_connect("*********************", "****", "*****") or die(mysql_error());
mysql_select_db("metrics") or die(mysql_error());
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$result = "SELECT * FROM tad WHERE id='$id'";
$result2 = mysql_query($result);
$rows = mysql_fetch_array($result2);
?>
<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="9"><strong>You are updating <?php echo $rows['rotname']; ?>:</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="<?php echo $rows['date']; ?>"></td>
<td align="center"><input name="userid" type="text" id="userid" value="<?php echo $rows['userid']; ?>" size="15"></td>
<td align="center"><input name="shift" type="text" id="shift" value="<?php echo $rows['shift']; ?>" size="15"></td>
<td align="center"><input name="rotname" type="text" id="rotname" value="<?php echo $rows['rotname']; ?>" size="15"></td>
<td align="center"><input name="rotationcomplete" type="text" id="rotationcomplete" value="<?php echo $rows['rotationcomplete']; ?>" size="15"></td>
<td align="center"><input name="totaltapesreq" type="text" id="totaltapesreq" value="<?php echo $rows['totaltapesreq']; ?>" size="15"></td>
<td align="center"><input name="totalentered" type="text" id="totalentered" value="<?php echo $rows['totalentered']; ?>" size="15"></td>
<td align="center"><input name="totalremoved" type="text" id="totalremoved" value="<?php echo $rows['totalremoved']; ?>" size="15"></td>
<td align="center"><input name="comments" type="text" id="comments" value="<?php echo $rows['comments']; ?>" size="15"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Code: Select all
<?php
// Connect to server and select database.
mysql_connect("*********************", "****", "*****") or die(mysql_error());
mysql_select_db("metrics") or die(mysql_error());
// update data in mysql database
$sql="UPDATE tad 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 "Metrics updated successfully";
echo "<BR>";
echo "<a href='listrecords.php'>Go back</a>";
}
else {
echo "ERROR";
}
?>
Code: Select all
mysql_query("UPDATE `table` SET update = '". time() ."'"); // This will not update your field if it's called update
mysql_query("UPDATE `table` SET `update` = '". time() ."'"); // This should work fine (as far as I know)
Code: Select all
// Make sure the information is good to go, this will disable people from tampering with your database
foreach( $_POST as $key => $value )
{
$_POST[$key] = addslashes(htmlentities($value));
}
// update data in mysql database
mysql_query("UPDATE `tad` SET
`date` = '{$_POST['date']}',
`userid` = '{$_POST['userid']}',
`shift` = '{$_POST['shift']}',
`rotname` = '{$_POST['rotname']}',
`rotationcomplete` = '{$_POST['rotationcomplete']}',
`totaltapesreq` = '{$_POST['totaltapesreq']}',
`totalentered` = '{$_POST['totalentered']}',
`totalremoved` = '{$_POST['totalremoved']}',
`comments` = '{$_POST['comments']}'
WHERE `id` = '". addslashes(htmlentities($_GET['id'])) ."'") or die( mysql_error() );
echo "Metrics update succesfully<br /> <a href=\"listrecords.php\">Go Back</a>";