Shattered Posted January 22, 2007 Share Posted January 22, 2007 I am kinda stuck on where to even start with working on this part of my little project. I want to be able to update a row, thats it. Im pretty much at the limits of my PHP knowledge and Im just doing a lot of guesswork now.This is what I have thus far:[b]index.php[/b][code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><title>PC Overview</title></head><body><a href="add_pc.php">Add a PC</a><br><a href="delete_pc.php">Remove a PC</a><br><br><br><?php$con = mysql_connect("localhost","root","");if(!$con){ die('Could not connect: ' . mysql_error());}mysql_select_db("PCLab", $con);$result = mysql_query("SELECT * FROM desktops");echo "<table border=1>";echo "<th>ID</th><th>Type</th><th>Name</th><th>Asset #</th><th>Service Tag</th><th>Status</th><th>Date Built</th><th>Lab Tech.</th><th>Lab Location</th><th>Deployed To</th><th>Tech.</th><th>Notes/Comments</th>";while($row = mysql_fetch_array($result)){ echo "<tr><td>".$row['ID']."</td><td>".$row['PC_TYPE']."</td><td>".$row['PC_NAME']."</td><td>".$row['PC_ASSET']."</td><td>".$row['PC_SERTAG']."</td><td>".$row['PC_STATUS']."</td><td>".$row['PC_BLDDATE']."</td><td>".$row['PC_BLDTECH']."</td><td>".$row['PC_LABLOC']."</td><td>".$row['PC_DEPLOYED']."</td><td>".$row['PC_BYWHO']."</td><td>".$row['PC_NOTES']."</td></tr>";}echo "</table>";mysql_close($con);?></body></html>[/code][b]add_pc.php[/b][code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"><title>Add a PC</title></head><body><div><a href="index.php">Home</a><br><br></div><form action="add_pc_result.php" method="post"><table><tr><td>Type</td><td><select name="pc_type"> <option value="GX260">GX260</option><option value="GX270">GX270</option> <option value="GX270MT">GX270MT</option><option value="GX280">GX280</option> <option value="GX280MT">GX280MT</option><option value="Precision360">Precision 360</option> <option value="Precision370">Precision 370</option><option value="Precision380">Precision 380</option> <option value="Precision390">Precision 390</option><option value="GX410">GX410</option> <option value="GX420">GX420</option><option value="GX530">GX530</option> <option value="GX620">GX620</option> </select></td></tr><tr><td>Name</td><td><input type="text" name="pc_name"></td></tr><tr><td>Asset #</td><td><input type="text" name="pc_asset"></td></tr><tr><td>Service Tag</td><td><input type="text" name="pc_sertag"></td></tr><tr><td>Status</td><td><select name="pc_status"> <option value="Ready">Ready</option> <option value="Deployed">Deployed</option> <option value="In Repair">In Repair</option> <option value="Donation">Donation</option> <option value="In Progress">In Progress</option> <option value="Warehouse">Warehouse</option> <option value="Building">Building</option> <option value="Rebuilt">Rebuild</option> </select></td></tr><tr><td>Date Built</td><td><input type="text" name="pc_blddate"></td></tr><tr><td>Lab Tech.</td><td><input type="text" name="pc_labtech"></td></tr><tr><td>Lab Location</td><td><input type="text" name="pc_labloc"></td></tr><tr><td>Deployed To</td><td><input type="text" name="pc_deployedto"></td></tr><tr><td>Tech.</td><td><input type="text" name="pc_tech"></td></tr><tr><td>Notes/Comments</td><td><input type="text" name="pc_notes"></td></tr><tr><td><input type="submit" value="Submit"></td><td><input type="reset"></td></tr></table></form></body></html>[/code][b]add_pc_result.php[/b][code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Page title</title></head><body><?php$con = mysql_connect("localhost","root","");if(!$con){ die('Could not connect: ' . mysql_error());}mysql_select_db("PCLab", $con);mysql_query("INSERT INTO desktops (PC_TYPE, PC_NAME, PC_ASSET, PC_SERTAG, PC_STATUS, PC_BLDDATE, PC_BLDTECH, PC_LABLOC, PC_DEPLOYED, PC_BYWHO, PC_NOTES) VALUES ('$_POST[pc_type]', '$_POST[pc_name]', '$_POST[pc_asset]', '$_POST[pc_sertag]', '$_POST[pc_status]', '$_POST[pc_blddate]', '$_POST[pc_labtech]', '$_POST[pc_labloc]', '$_POST[pc_deployedto]', '$_POST[pc_tech]', '$_POST[pc_notes]')");if(!mysql_query){ die('Error: ' . mysql_error());}else{ echo "<a href=index.php>Back to Main</a>"; echo "<br />"; echo "<a href=add_pc.php>Add another PC</a>"; echo "<br />"; echo "1 Record Added";}mysql_close($con);?></body></html>[/code][b]delete_pc.php[/b][code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Remove a PC</title></head><body><a href="index.php">Back to Main</a><form action="delete_pc_result.php" method="post"><table><tr><td>Asset #</td><td><input type="text" name="pc_asset"></td><tr><td><input type="submit" value="Submit"></td><td><input type="reset"></td></tr></table></form></body></html>[/code][b]delete_pc_result.php[/b][code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>Page title</title></head><body><?php$con = mysql_connect("localhost","root","");if(!$con){ die('Could not connect: ' . mysql_error());}mysql_select_db("PCLab", $con);mysql_query("DELETE FROM desktops WHERE PC_ASSET = '$_POST[pc_asset]'");if(!mysql_query){ die('Error: ' . mysql_error());}else{ echo "<a href=index.php>Back to Main</a>"; echo "<br />"; echo "<a href=delete_pc.php>Remove another PC</a>"; echo "<br />"; echo "1 Record Removed";}mysql_close($con);?></body></html>[/code]MySQL fields:ID, PC_TYPE, PC_NAME, PC_ASSET, PC_SERTAG, PC_STATUS, PC_BLDDATE, PC_BLDTECH, PC_LABLOC, PC_DEPLOYED, PC_BYWHO, PC_NOTES Quote Link to comment https://forums.phpfreaks.com/topic/35263-updating-fields-in-a-table/ Share on other sites More sharing options...
marcus Posted January 22, 2007 Share Posted January 22, 2007 [code=php:0]$sql = "UPDATE `tablename` SET `field1` ='$var1', `field2` ='$var2' WHERE `id` =$userid";$res = mysql_query($sql) or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35263-updating-fields-in-a-table/#findComment-166587 Share on other sites More sharing options...
Shattered Posted January 22, 2007 Author Share Posted January 22, 2007 Okay I understand that part. Is there a way so that I can change my "ID" column into checkboxes, so that I would be able to select one or more systems and update them that way, and then actually be able to implement that code? Quote Link to comment https://forums.phpfreaks.com/topic/35263-updating-fields-in-a-table/#findComment-166603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.