SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help Updating MySQL database tables

    Hello I have created a MySQL database and tables with vehicle information and maintenance information. I have added an update link in the table output, so maintenance information can be updated. I click the link and it takes me to the maintenance html form I created. when I hit submit I have it sending to the update script. It updates all the records not just the record I selected update on. Here is the code for my table output page where I have the option to update a record. Could the problem be here?

    Here is the code I have for the pages involved.

    Form Page:
    PHP Code:
    <?php require_once("dbcon.php"); ?>
    <?php 
    require_once("functions.php"); ?>
    <?php
    // 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);
    ?>

    <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">Maintenace/Repair Issues Reported:</th>
                  <td>
                     <textarea name="issues_reported" rows="3" cols="27"></textarea>
                 </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
                        &nbsp;
                        <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>
                 <tr valign="baseline">
                   <td nowrap align="right">&nbsp;</td>
                   <td><input type="submit" value="Insert record"></td>
                 </tr>
               </table>
               <input type="hidden" name="MM_insert" value="form1">
             </form>
             <a href="maint_list_update.php">Cancel</a>
             <p>&nbsp;</p>
           </section>
      <!-- end .content --></h2>
        </section>
    </body>
    </html>
    Update Page:
    PHP Code:
    <?php require_once("dbcon.php"); ?>
    <?php 
    require_once("functions.php"); ?>
    <?php
        $date_next_maint 
    mysql_prep($_POST['date_next_maint']);
        
    $issues_reported mysql_prep($_POST['issues_reported']);
        
    $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 
    "UPDATE service_info SET `date_next_maint`='$date_next_maint', `issues_reported`='$issues_reported', `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'";
        
    $result mysql_query($query$connection);
        if (
    $result) {
            
    // Success!
            
    redirect_to("maint_list_update.php");
        } else {
            
    // Display error message.
            
    echo "<p>Maintenance Info Creation Failed.</p>";
            echo 
    "<p>" mysql_error() . "</p>";
        }
    ?>

    Update Record Page -
    PHP Code:
    <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>
    Please help and a great thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You need to add a WHERE clause to your update query, and specify the unique key that identifies the row to be updated.
    Something like
    Code:
    WHERE maintenance_id = $value

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Your form has to pass along the id number of the record:

    Use a hidden field for that:
    PHP Code:
    <input type=hidden name=id value $id /> 
    Your form handler should then pick up that id and the update clause should read more like:
    PHP Code:
    "UPDATE service_info 
    SET `date_next_maint`='
    $date_next_maint
    // etc and then:
    WHERE id = 
    $id;"  // JUST update one record! 

  4. #4
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have updated the code with the WHERE id=$id and I have added the hidden field to the form, I am now getting this error

    Parse error: syntax error, unexpected '(' in /data/9/0/28/4/517493/user/528148/htdocs/jednewdb/updated_maint.php on line 19

    Here is updated code
    PHP Code:
    <?php require_once("dbcon.php"); ?>
    <?php 
    require_once("functions.php"); ?>
    <?php
        $date_next_maint 
    mysql_prep($_POST['date_next_maint']);
        
    $issues_reported mysql_prep($_POST['issues_reported']);
        
    $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 
    "UPDATE service_info SET `date_next_maint`='$date_next_maint', `issues_reported`='$issues_reported', `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>";
        }
    ?>

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code that is in line number 19 of /data/9/0/28/4/517493/user/528148/htdocs/jednewdb/updated_maint.php file?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here are all the updated files, I am getting a new error now and on the form page there is no id in the url.

    Record page where you select the record to update -

    PHP Code:
    <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>
    The form page where you fill in the changes to the table

    PHP Code:
    <?php session_start();?>
    <?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 $tbl_name 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">Maintenace/Repair Issues Reported:</th>
                  <td>
                     <textarea name="issues_reported" rows="3" cols="27"></textarea>
                 </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
                        &nbsp;
                        <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">&nbsp;</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>&nbsp;</p>
           </section>
      <!-- end .content --></h2>
        </section>
    </body>
    </html>
    This is the update page that the form page is submitted to and should result in a new updated query.
    PHP Code:
    <?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']);
        
    $issues_reported mysql_prep($_POST['issues_reported']);
        
    $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 
    "UPDATE service_info SET `date_next_maint`='$date_next_maint', `issues_reported`='$issues_reported', `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>";
    ?>

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see the error on line number 19 of your update file. Even other codes above you have given have any syntax errors. What exactly the new error message is now? And what is the file and code that is giving you the error? Can you say that please?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    PHP Code:
    <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 Code:
    <?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
                        &nbsp;
                        <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">&nbsp;</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>&nbsp;</p>
           </section>
      <!-- end .content --></h2>
        </section>
    </body>
    </html>
    Here is update file updated_maint

    PHP Code:
    <?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);
    ?>

  9. #9
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INSERT INTO statement does not have WHERE clause. Only DELETE & UPDATE statements have WHERE clause. And INSERT INTO statement syntax is wrong that you have used in. So correct one should something like this:
    Code php:
    $query = "INSERT INTO service_info SET 
    `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'";
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  10. #10
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you....I just realized the INSERT clause didn't take WHERE, so I switched back to UPDATE and now I still have this 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 '' at line 5

    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 '' at line 5 SQL: UPDATE service_info SET `date_next_maint`='testing', `date_reported`='testing', `scheduled_service_date`='testing', `service_performed`='', `date_service_performed`='testing', `date_of_followup`='',`service_in_progress`='', `date_return_use`='', `time_return_use`='', `issues_nonrepairable`='', `date_nonrepairable_issues`='', `comments` ='' WHERE id=

  11. #11
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that you do not have any value in $id variable.
    WHERE id=?? // here should be some value after =.

    Try echoing/printing the query and run it outside of the PHP (phpmyadmin) and see if that works.
    PHP Code:
    echo $query
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  12. #12
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did like you said and added print $query and this is what it displayed in browser

    Notice: Undefined index: id in /data/9/0/28/4/517493/user/528148/htdocs/jednewdb/updated_maint.php on line 9

    Notice: Undefined index: service_in_progress in /data/9/0/28/4/517493/user/528148/htdocs/jednewdb/updated_maint.php on line 16
    UPDATE service_info SET `date_next_maint`='8/23/12', `date_reported`='8/20/12', `scheduled_service_date`='8/20/12', `service_performed`='', `date_service_performed`='8/20/12', `date_of_followup`='',`service_in_progress`='', `date_return_use`='8/24/12', `time_return_use`='23:00', `issues_nonrepairable`='', `date_nonrepairable_issues`='testing', `comments` ='' WHERE id=''

  13. #13
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    From a quick look at your code, if the $id is supposed to be generated from the SESSION and is clearly not appearing, just before you echo your query out as Raju said, add this line:

    PHP Code:
    var_dump$_SESSION ); 
    That will tell you if $_SESSION['id'] exits and what it contains.

  14. #14
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just solved....I forgot session_start() on maint_update page


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •