flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Here is the code to the page that is suppose to give the id when you select a record to update. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Service Order Database</title> <link href="nav.css" rel="stylesheet" type="text/css"><!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <?php require_once("dbcon.php"); ?> <?php require_once("functions.php"); ?> <?php $query="SELECT * FROM service_info ORDER BY id"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; // process form when posted if(isset($_POST['value'])) { if($_POST['value'] == 'Engine') { // query to get all Engine records $query = "SELECT * FROM servifce_info WHERE issues_reported='Engine'"; }elseif($_POST['value'] == 'Transmission') { // query to get all Transmission records $query = "SELECT * FROM servifce_info WHERE issues_reported='Transmission'"; }elseif($_POST['value'] == 'Differential') { // query to get all Differential records $query = "SELECT * FROM servifce_info WHERE issues_reported='Differential'"; }elseif($_POST['value'] == 'Electrical') { // query to get all Electrical records $query = "SELECT * FROM servifce_info WHERE issues_reported='Electrical'"; }elseif($_POST['value'] == 'Tires') { // query to get all Tires records $query = "SELECT * FROM servifce_info WHERE issues_reported='Tires'"; }elseif($_POST['value'] == 'Brakes') { // query to get all Brakes records $query = "SELECT * FROM servifce_info WHERE issues_reported='Brakes'"; }elseif($_POST['value'] == 'HVAC') { // query to get all HVAC records $query = "SELECT * FROM servifce_info WHERE issues_reported='HVAC'"; }elseif($_POST['value'] == 'Lighting') { // query to get all Lighting records $query = "SELECT * FROM servifce_info WHERE issues_reported='Lighting'"; }elseif($_POST['value'] == 'Accident Damage') { // query to get all Accident Damage records $query = "SELECT * FROM servifce_info WHERE issues_reported='Accident Damage'"; } else { // query to get all records $query = "SELECT * FROM servifce_info "; } mysql_close(); } ?> <html> <head></head> <body> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > <select name="value"> <option value="all">All</option> <option value="Engine">Engine</option> <option value="Transmission">Transmission</option> <option value="Differential">Differential</option> <option value="Electrical">Electrical</option> <option value="Tires">Tires</option> <option value="Brakes">Brakes</option> <option value="HVAC">HVAC</option> <option value="Lighting">Lighting</option> <option value="Accident">Accident</option> </select> <br /> <input type='submit' value = 'Filter'> </form> <div id="nav"> <ul> <li><a href="order_vehicle_name.php" title=""> ORDER BY VEHICLE NAME</a></li> <li><a href="order_vehicle_number.php" title=""> ORDER BY VEHICLE NUMBER</a></li> <li><a href="order_location.php" title=""> ORDER BY LOCATION</a></li> <li><a href="order_status.php" title=""> ORDER BY STATUS</a></li> <li><a href="order_issues_reported.php" title=""> ORDER REPORTED ISSUES</a></li> <li><a href="order_id.php" title=""> ORDER BY ID</a></li> <li><a href="index.php">LOG OUT</a></li> </ul> </div> <table border="1" cellspacing="5" cellpadding="5"> <tr> <th><font face="Arial, Helvetica, sans-serif">ID</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Number</font></th> <th><font face="Arial, Helvetica, sans-serif">Location</font></th> <th><font face="Arial, Helvetica, sans-serif">Status</font></th> <th><font face="Arial, Helvetica, sans-serif">RTS</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Reading Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Date of next scheduled maintenance</font></th> <th><font face="Arial, Helvetica, sans-serif">Maintenace/Repair Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Scheduled Service Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Repair Service Performed W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Service Performed</font></th> <th><font face="Arial, Helvetica, sans-serif">Date OF Follow-up</font></th> <th><font face="Arial, Helvetica, sans-serif">Service In Progress 0=NO 1=YES</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Return To Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Time Return Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Nonrepaiable Issues Found W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Found</font></th> <th><font face="Arial, Helvetica, sans-serif">Parts Cost</font></th> <th><font face="Arial, Helvetica, sans-serif">Hours Worked</font></th> <th><font face="Arial, Helvetica, sans-serif">Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Update</font></th> </tr> <?php $i=0; while ($i < $num) { $field1=mysql_result($result,$i,"id"); $field2=mysql_result($result,$i,"name"); $field3=mysql_result($result,$i,"number"); $field4=mysql_result($result,$i,"location"); $field5=mysql_result($result,$i,"status"); $field6=mysql_result($result,$i,"rts"); $field7=mysql_result($result,$i,"odomread"); $field8=mysql_result($result,$i,"odomdate"); $field9=mysql_result($result,$i,"date_next_maint"); $field10=mysql_result($result,$i,"issues_reported"); $field11=mysql_result($result,$i,"date_reported"); $field12=mysql_result($result,$i,"scheduled_service_date"); $field13=mysql_result($result,$i,"service_performed"); $field14=mysql_result($result,$i,"date_service_performed"); $field15=mysql_result($result,$i,"date_of_followup"); $field16=mysql_result($result,$i,"service_in_progress"); $field17=mysql_result($result,$i,"date_return_use"); $field18=mysql_result($result,$i,"time_return_use"); $field19=mysql_result($result,$i,"issues_nonrepairable"); $field20=mysql_result($result,$i,"date_nonrepairable_issues"); $field21=mysql_result($result,$i,"parts_cost"); $field22=mysql_result($result,$i,"hours"); $field23=mysql_result($result,$i,"comments"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field6; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field8; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field9; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field10; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field12; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field13; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field14; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field15; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field16; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field17; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field18; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field19; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field20; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field21; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field22; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field23; ?></font></td> <td><a href="maint_update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php $i++; } ?> </body> </html> I realize the id is blank because there is no id in the url but I don't see anything wrong in my code that is causing no id to be in the url. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372923 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 I am very new to php and trying to teach myself as I go with the help of fellow coders like yourself, so I apologize for the lack in understanding some times, and I do appreciate everything everyone has done to help. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372924 Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 <td><a href="maint_update.php?id=<? echo $rows['id']; ?>">update</a></td> 1. Don't use short tags, use <?php not <? 2. You don't have $row defined anywhere. 3. You need to turn on error_reporting to E_ALL so you can see this stuff as errors/notices. 4. You have $field1=mysql_result($result,$i,"id"); at the very start of your loop, so you can use $field1. Although you should go through and rename all of those to be USEFUL names, since you can't remember what $field1 is by the time you need it. 5. Look at mysql_fetch_assoc, specifically the examples on that page. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372926 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Thank you I will work on it more and post and updates!! Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372929 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 URL is now showing maint_update.php?id=1 regardless of what record I click to update. Did I do this right, replacing $row with $field1? <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Service Order Database</title> <link href="nav.css" rel="stylesheet" type="text/css"><!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <?php require_once("dbcon.php"); ?> <?php require_once("functions.php"); ?> <?php $query="SELECT * FROM service_info ORDER BY id"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; // process form when posted if(isset($_POST['value'])) { if($_POST['value'] == 'Engine') { // query to get all Engine records $query = "SELECT * FROM servifce_info WHERE issues_reported='Engine'"; }elseif($_POST['value'] == 'Transmission') { // query to get all Transmission records $query = "SELECT * FROM servifce_info WHERE issues_reported='Transmission'"; }elseif($_POST['value'] == 'Differential') { // query to get all Differential records $query = "SELECT * FROM servifce_info WHERE issues_reported='Differential'"; }elseif($_POST['value'] == 'Electrical') { // query to get all Electrical records $query = "SELECT * FROM servifce_info WHERE issues_reported='Electrical'"; }elseif($_POST['value'] == 'Tires') { // query to get all Tires records $query = "SELECT * FROM servifce_info WHERE issues_reported='Tires'"; }elseif($_POST['value'] == 'Brakes') { // query to get all Brakes records $query = "SELECT * FROM servifce_info WHERE issues_reported='Brakes'"; }elseif($_POST['value'] == 'HVAC') { // query to get all HVAC records $query = "SELECT * FROM servifce_info WHERE issues_reported='HVAC'"; }elseif($_POST['value'] == 'Lighting') { // query to get all Lighting records $query = "SELECT * FROM servifce_info WHERE issues_reported='Lighting'"; }elseif($_POST['value'] == 'Accident Damage') { // query to get all Accident Damage records $query = "SELECT * FROM servifce_info WHERE issues_reported='Accident Damage'"; } else { // query to get all records $query = "SELECT * FROM servifce_info "; } mysql_close(); } ?> <html> <head></head> <body> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > <select name="value"> <option value="all">All</option> <option value="Engine">Engine</option> <option value="Transmission">Transmission</option> <option value="Differential">Differential</option> <option value="Electrical">Electrical</option> <option value="Tires">Tires</option> <option value="Brakes">Brakes</option> <option value="HVAC">HVAC</option> <option value="Lighting">Lighting</option> <option value="Accident">Accident</option> </select> <br /> <input type='submit' value = 'Filter'> </form> <div id="nav"> <ul> <li><a href="order_vehicle_name.php" title=""> ORDER BY VEHICLE NAME</a></li> <li><a href="order_vehicle_number.php" title=""> ORDER BY VEHICLE NUMBER</a></li> <li><a href="order_location.php" title=""> ORDER BY LOCATION</a></li> <li><a href="order_status.php" title=""> ORDER BY STATUS</a></li> <li><a href="order_issues_reported.php" title=""> ORDER REPORTED ISSUES</a></li> <li><a href="order_id.php" title=""> ORDER BY ID</a></li> <li><a href="index.php">LOG OUT</a></li> </ul> </div> <table border="1" cellspacing="5" cellpadding="5"> <tr> <th><font face="Arial, Helvetica, sans-serif">ID</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Number</font></th> <th><font face="Arial, Helvetica, sans-serif">Location</font></th> <th><font face="Arial, Helvetica, sans-serif">Status</font></th> <th><font face="Arial, Helvetica, sans-serif">RTS</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Reading Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Date of next scheduled maintenance</font></th> <th><font face="Arial, Helvetica, sans-serif">Maintenace/Repair Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Scheduled Service Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Repair Service Performed W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Service Performed</font></th> <th><font face="Arial, Helvetica, sans-serif">Date OF Follow-up</font></th> <th><font face="Arial, Helvetica, sans-serif">Service In Progress 0=NO 1=YES</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Return To Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Time Return Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Nonrepaiable Issues Found W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Found</font></th> <th><font face="Arial, Helvetica, sans-serif">Parts Cost</font></th> <th><font face="Arial, Helvetica, sans-serif">Hours Worked</font></th> <th><font face="Arial, Helvetica, sans-serif">Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Update</font></th> </tr> <?php $i=0; while ($i < $num) { $field1=mysql_result($result,$i,"id"); $field2=mysql_result($result,$i,"name"); $field3=mysql_result($result,$i,"number"); $field4=mysql_result($result,$i,"location"); $field5=mysql_result($result,$i,"status"); $field6=mysql_result($result,$i,"rts"); $field7=mysql_result($result,$i,"odomread"); $field8=mysql_result($result,$i,"odomdate"); $field9=mysql_result($result,$i,"date_next_maint"); $field10=mysql_result($result,$i,"issues_reported"); $field11=mysql_result($result,$i,"date_reported"); $field12=mysql_result($result,$i,"scheduled_service_date"); $field13=mysql_result($result,$i,"service_performed"); $field14=mysql_result($result,$i,"date_service_performed"); $field15=mysql_result($result,$i,"date_of_followup"); $field16=mysql_result($result,$i,"service_in_progress"); $field17=mysql_result($result,$i,"date_return_use"); $field18=mysql_result($result,$i,"time_return_use"); $field19=mysql_result($result,$i,"issues_nonrepairable"); $field20=mysql_result($result,$i,"date_nonrepairable_issues"); $field21=mysql_result($result,$i,"parts_cost"); $field22=mysql_result($result,$i,"hours"); $field23=mysql_result($result,$i,"comments"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field6; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field8; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field9; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field10; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field12; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field13; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field14; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field15; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field16; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field17; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field18; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field19; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field20; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field21; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field22; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field23; ?></font></td> <td><a href="maint_update.php?id=<?php echo $field1['id']; ?>">update</a></td> </tr> <?php $i++; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372958 Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 No. Where you have <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> Does that output the IDs as you expect them? Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372960 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Yes that outputs the IDs as they are in the database like I expect it should. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372961 Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 So why would you expect these two lines to echo the SAME number? This is what I mean by thinking it through. Look at what you're doing. <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> <td><a href="maint_update.php?id=<?php echo $field1['id']; ?>">update</a></td> Finally, if you don't set up your error reporting, this is the last help I am offering on this post. You can find all of these bugs with proper error reporting turned on, and you would be able to read messages explaining it so no one here has to type them for you. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372963 Share on other sites More sharing options...
cyberRobot Posted August 27, 2012 Share Posted August 27, 2012 If you haven't done so already, the form page needs to be updated to pass the ID for the row being updated. The update page needs to read in that ID so it can be used in the query. Sorry, I didn't see there was a third page of responses. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372967 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 I have added this error_reporting(E_ALL); to show errors. Is that the wrong code to add? It's not showing anything. I expected the first line <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> to display the ID in the display table (which is what it is doing) I expected the second line <td><a href="maint_update.php?id=<?php echo $field1['id']; ?>">update</a></td> to tell the maint_update page which record to update. I thought they would have to be the same in order to do that. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372970 Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 You need to turn error_reporting on in your php.ini, if you don't see errors from this page. $field1 cannot be both an integer and an array. I think you need to read some basic PHP tutorials because you don't seem to understand at all what you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372971 Share on other sites More sharing options...
cyberRobot Posted August 27, 2012 Share Posted August 27, 2012 First, the code could be easier to maintain if you used mysql_fetch_array() instead of mysql_result(). Instead of this <?php $i=0; while ($i < $num) { $field1=mysql_result($result,$i,"id"); $field2=mysql_result($result,$i,"name"); $field3=mysql_result($result,$i,"number"); $field4=mysql_result($result,$i,"location"); $field5=mysql_result($result,$i,"status"); $field6=mysql_result($result,$i,"rts"); $field7=mysql_result($result,$i,"odomread"); $field8=mysql_result($result,$i,"odomdate"); $field9=mysql_result($result,$i,"date_next_maint"); $field10=mysql_result($result,$i,"issues_reported"); $field11=mysql_result($result,$i,"date_reported"); $field12=mysql_result($result,$i,"scheduled_service_date"); $field13=mysql_result($result,$i,"service_performed"); $field14=mysql_result($result,$i,"date_service_performed"); $field15=mysql_result($result,$i,"date_of_followup"); $field16=mysql_result($result,$i,"service_in_progress"); $field17=mysql_result($result,$i,"date_return_use"); $field18=mysql_result($result,$i,"time_return_use"); $field19=mysql_result($result,$i,"issues_nonrepairable"); $field20=mysql_result($result,$i,"date_nonrepairable_issues"); $field21=mysql_result($result,$i,"parts_cost"); $field22=mysql_result($result,$i,"hours"); $field23=mysql_result($result,$i,"comments"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field6; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field8; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field9; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field10; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field12; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field13; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field14; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field15; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field16; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field17; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field18; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field19; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field20; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field21; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field22; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field23; ?></font></td> <td><a href="maint_update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php $i++; } ?> You could do this: <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['id']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['name']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['number']; ?></font></td> <!-- You can do the rest ;-) --> <td><a href="maint_update.php?id=<?php echo $row['id']; ?>">update</a></td> </tr> <?php } ?> If you do that, does the ID show up as expected in the following portion? <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['id']; ?></font></td> <!-- ... --> <td><a href="maint_update.php?id=<?php echo $row['id']; ?>">update</a></td> Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372980 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Thank you that did help, I am now getting the correct ID, I am looking further into the new error I am getting now. Error - Maintenance Info Creation Failed. Unknown column 'comments' in 'field list' Error: Unknown column 'comments' in 'field list' SQL: UPDATE service_info SET `date_next_maint`='testing', `issues_reported`='', `date_reported`='', `scheduled_service_date`='', `service_performed`='', `date_service_performed`='', `date_of_followup`='',`service_in_progress`='', `date_return_use`='', `time_return_use`='', `issues_nonrepairable`='', `date_nonrepairable_issues`='', `comments` ='' WHERE id=15 Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372990 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Its a typing error I made I just have to find it. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372991 Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 It tells you exactly what is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372992 Share on other sites More sharing options...
cyberRobot Posted August 27, 2012 Share Posted August 27, 2012 Does your database table (service_info) have a column named "comments"? Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1372994 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 That was the problem yes, Thank you all very much for the help. It is greatly appreciated and I learned a lot on where I made mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373005 Share on other sites More sharing options...
cyberRobot Posted August 27, 2012 Share Posted August 27, 2012 No problem. There's one last thing I wanted to mention, but I thought I would wait until the initial question was answered. It's highly recommended that you avoid using PHP_SELF as the form action. <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > You could hard code the value instead. PHP_SELF should be avoided for security reasons. For more information, see: http://seancoates.com/blogs/xss-woes Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373022 Share on other sites More sharing options...
flashbangpro Posted August 27, 2012 Author Share Posted August 27, 2012 Thank you, I will add this to my coding arsenal. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373024 Share on other sites More sharing options...
Christian F. Posted August 27, 2012 Share Posted August 27, 2012 I've posted a solution to enable the use of PHP_SELF, without the associated security risk. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373030 Share on other sites More sharing options...
flashbangpro Posted August 28, 2012 Author Share Posted August 28, 2012 Ok I had everything working yesterday, but when I updated a few fields and then when back to update a few others, it deleted the previous updated fields and set them to blank, so not I am trying INSERT INTO service_info WHERE id=$id and this is the error I get and these are the updated pages involved. Maintenance Info Creation Failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`date_next_maint`='testing', `date_reported`='testing', `scheduled_service_d' at line 1 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`date_next_maint`='testing', `date_reported`='testing', `scheduled_service_d' at line 1 SQL: INSERT INTO service_info `date_next_maint`='testing', `date_reported`='testing', `scheduled_service_date`='testing', `service_performed`='', `date_service_performed`='', `date_of_followup`='',`service_in_progress`='1', `date_return_use`='', `time_return_use`='', `issues_nonrepairable`='', `date_nonrepairable_issues`='', `comments` ='' WHERE id= When I go to maint_update page, the url shows id='whatever record clicked' so it is getting the id from the records page. Here is records page service_list_update <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Service Order Database</title> <link href="nav.css" rel="stylesheet" type="text/css"><!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <?php require_once("dbcon.php"); ?> <?php require_once("functions.php"); ?> <?php $query="SELECT * FROM service_info ORDER BY id"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; // process form when posted if(isset($_POST['value'])) { if($_POST['value'] == 'Engine') { // query to get all Engine records $query = "SELECT * FROM servifce_info WHERE issues_reported='Engine'"; }elseif($_POST['value'] == 'Transmission') { // query to get all Transmission records $query = "SELECT * FROM servifce_info WHERE issues_reported='Transmission'"; }elseif($_POST['value'] == 'Differential') { // query to get all Differential records $query = "SELECT * FROM servifce_info WHERE issues_reported='Differential'"; }elseif($_POST['value'] == 'Electrical') { // query to get all Electrical records $query = "SELECT * FROM servifce_info WHERE issues_reported='Electrical'"; }elseif($_POST['value'] == 'Tires') { // query to get all Tires records $query = "SELECT * FROM servifce_info WHERE issues_reported='Tires'"; }elseif($_POST['value'] == 'Brakes') { // query to get all Brakes records $query = "SELECT * FROM servifce_info WHERE issues_reported='Brakes'"; }elseif($_POST['value'] == 'HVAC') { // query to get all HVAC records $query = "SELECT * FROM servifce_info WHERE issues_reported='HVAC'"; }elseif($_POST['value'] == 'Lighting') { // query to get all Lighting records $query = "SELECT * FROM servifce_info WHERE issues_reported='Lighting'"; }elseif($_POST['value'] == 'Accident Damage') { // query to get all Accident Damage records $query = "SELECT * FROM servifce_info WHERE issues_reported='Accident Damage'"; } else { // query to get all records $query = "SELECT * FROM servifce_info "; } mysql_close(); } ?> <html> <head></head> <body> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > <select name="value"> <option value="all">All</option> <option value="Engine">Engine</option> <option value="Transmission">Transmission</option> <option value="Differential">Differential</option> <option value="Electrical">Electrical</option> <option value="Tires">Tires</option> <option value="Brakes">Brakes</option> <option value="HVAC">HVAC</option> <option value="Lighting">Lighting</option> <option value="Accident">Accident</option> </select> <br /> <input type='submit' value = 'Filter'> </form> <div id="nav"> <ul> <li><a href="order_vehicle_name.php" title=""> ORDER BY VEHICLE NAME</a></li> <li><a href="order_vehicle_number.php" title=""> ORDER BY VEHICLE NUMBER</a></li> <li><a href="order_location.php" title=""> ORDER BY LOCATION</a></li> <li><a href="order_status.php" title=""> ORDER BY STATUS</a></li> <li><a href="order_issues_reported.php" title=""> ORDER REPORTED ISSUES</a></li> <li><a href="order_id.php" title=""> ORDER BY ID</a></li> <li><a href="index.php">LOG OUT</a></li> </ul> </div> <table border="1" cellspacing="5" cellpadding="5"> <tr> <th><font face="Arial, Helvetica, sans-serif">ID</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Vehicle Number</font></th> <th><font face="Arial, Helvetica, sans-serif">Location</font></th> <th><font face="Arial, Helvetica, sans-serif">Status</font></th> <th><font face="Arial, Helvetica, sans-serif">RTS</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Odometer Reading Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Date of next scheduled maintenance</font></th> <th><font face="Arial, Helvetica, sans-serif">Maintenance/Repair Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Scheduled Service Date Issues Reported</font></th> <th><font face="Arial, Helvetica, sans-serif">Repair Service Performed W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Service Performed</font></th> <th><font face="Arial, Helvetica, sans-serif">Date OF Follow-up</font></th> <th><font face="Arial, Helvetica, sans-serif">Service In Progress 0=NO 1=YES</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Return To Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Time Return Use</font></th> <th><font face="Arial, Helvetica, sans-serif">Nonrepaiable Issues Found W/Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Date Issues Found</font></th> <th><font face="Arial, Helvetica, sans-serif">Parts Cost</font></th> <th><font face="Arial, Helvetica, sans-serif">Hours Worked</font></th> <th><font face="Arial, Helvetica, sans-serif">Comments</font></th> <th><font face="Arial, Helvetica, sans-serif">Update</font></th> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['id']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['name']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['number']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['location']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['status']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['rts']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['odomread']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['odomdate']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_next_maint']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['issues_reported']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_reported']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['scheduled_service_date']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['service_performed']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_service_performed']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_of_followup']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['service_in_progress']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_return_use']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['time_return_use']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['issues_nonrepairable']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['date_nonrepairable_issues']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['parts_cost']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['hours']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['comments']; ?></font></td> <td><a href="maint_update.php?id=<?php echo $row['id']; ?>">update</a></td> </tr> <?php } ?> <?php error_reporting(E_ALL); ?> </body> </html> Here is update page maint_update <?php require_once("dbcon.php"); ?> <?php require_once("functions.php"); ?> <?php // get value of id that sent from address bar $id=$_GET['id']; $_SESSION['id'] = $id; // Retrieve data from database $sql="SELECT * FROM service_info WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <html> <body> <h1>Maintenace Report </h1> <section> <section> <form method="post" name="form1" action="updated_maint.php"> <table align="center"> <tr valign="baseline"> <th nowrap align="right">Date of next scheduled maintenance:</th> <td> <input type="text" name="date_next_maint" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Date That Maintenace/Repair Issues Reported:</th> <td> <input type="text" name="date_reported" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Scheduled Service Date That Maintenace/Repair Issues Reported:</th> <td> <input type="text" name="scheduled_service_date" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Maintenace/Repair Service Performed W/Comments:</th> <td> <textarea name="service_performed" rows="3" cols="27"></textarea> </tr> <tr valign="baseline"> <th nowrap align="right">Date Maintenace/Repair Service Performed:</th> <td><input type="text" name="date_service_performed" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Date OF Follow-up Work / If Needed:</th> <td> <input type="text" name="date_of_followup" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Service In Progress:</th> <td> <input type="radio" name="service_in_progress" value="0" /> No <input type="radio" name="service_in_progress" value="1" /> Yes </tr> <tr valign="baseline"> <th nowrap align="right">Date Return To Use:</th> <td> <input type="text" name="date_return_use" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Time Return Use:</th> <td> <input type="text" name="time_return_use" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Nonrepaiable Issues Found W/Comments:</th> <td> <textarea name="issues_nonrepairable" rows="3" cols="27"></textarea> </tr> <tr valign="baseline"> <th nowrap align="right">Date Nonrepaiable Issues Found:</th> <td> <input type="text" name="date_nonrepairable_issues" value="" size="32"> </tr> <tr valign="baseline"> <th nowrap align="right">Comments:</th> <td> <textarea name="comments" rows="3" cols="27"></textarea> </tr> <input type="hidden" name="id" value = "$id" /> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insert record"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> <a href="service_list_update.php">Cancel</a> <p> </p> </section> <!-- end .content --></h2> </section> </body> </html> Here is update file updated_maint <?php session_start();?> <?php require_once("dbcon.php"); ?> <?php require_once("functions.php"); ?> <?php $id = $_SESSION['id']; $date_next_maint = mysql_prep($_POST['date_next_maint']); $date_reported = mysql_prep($_POST['date_reported']); $scheduled_service_date = mysql_prep($_POST['scheduled_service_date']); $service_performed = mysql_prep($_POST['service_performed']); $date_service_performed = mysql_prep($_POST['date_service_performed']); $date_of_followup = mysql_prep($_POST['date_of_followup']); $service_in_progress = mysql_prep($_POST['service_in_progress']); $date_return_use = mysql_prep($_POST['date_return_use']); $time_return_use = mysql_prep($_POST['time_return_use']); $issues_nonrepairable = mysql_prep($_POST['issues_nonrepairable']); $date_nonrepairable_issues = mysql_prep($_POST['date_nonrepairable_issues']); $comments = mysql_prep($_POST['comments']); ?> <?php $query = "INSERT INTO service_info `date_next_maint`='$date_next_maint', `date_reported`='$date_reported', `scheduled_service_date`='$scheduled_service_date', `service_performed`='$service_performed', `date_service_performed`='$date_service_performed', `date_of_followup`='$date_of_followup',`service_in_progress`='$service_in_progress', `date_return_use`='$date_return_use', `time_return_use`='$time_return_use', `issues_nonrepairable`='$issues_nonrepairable', `date_nonrepairable_issues`='$date_nonrepairable_issues', `comments` ='$comments' WHERE id=$id"; $result = mysql_query($query, $connection); if ($result) { // Success! redirect_to("service_list_update.php"); } else { // Display error message. echo "<p>Maintenance Info Creation Failed.</p>"; echo "<p>" . mysql_error() . "</p>"; } echo "<p>Error: " . mysql_error() . " SQL: $query</p>"; ?> <?php ini_set('display_errors',1); error_reporting(E_ALL); ?> Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373183 Share on other sites More sharing options...
Jessica Posted August 28, 2012 Share Posted August 28, 2012 You're using update syntax, the insert syntax is different. Are you trying to insert or update? Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373186 Share on other sites More sharing options...
flashbangpro Posted August 28, 2012 Author Share Posted August 28, 2012 When I used update and was only updating one field it blanked out all the others so I thought using insert would just change the field I needed. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373189 Share on other sites More sharing options...
Jessica Posted August 28, 2012 Share Posted August 28, 2012 Seriously at this point I'm starting to think you're trolling. You set the fields to blank values. Of course they are blank. What did you expect? Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373191 Share on other sites More sharing options...
flashbangpro Posted August 28, 2012 Author Share Posted August 28, 2012 Why would I be trolling? If I didn't seriously need help with this I wouldn't take my time to make suggested adjustments and keep reposting. Quote Link to comment https://forums.phpfreaks.com/topic/267643-help-updating-mysql-database-tables/page/2/#findComment-1373199 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.