hi....
i m fetching 3 fields from two different tables that is ecode and edate from emp_company table and scode from emp_shift table.....and after fetching the records i want to change the value of any of the record and want to insert as a new record in emp_shift table.........but my code is not working.....please help me out.....

<html>
    <body bgcolor="E6E6FA">
    <!--<h3> <p align="center"> Shift Updation Table </p></h3> !-->
    <?
    $con=mysql_connect("localhost","root","root");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
   mysql_select_db("master", $con);
   $result=mysql_query("SELECT emp_company.ecode, emp_shift.scode FROM emp_company, emp_shift where emp_company.ecode=emp_shift.ecode");
   echo "<table border='1'><caption> Employee 's Record Updation Table</caption> <BR><BR><BR><BR>
   <tr>
   <th >Empoyee Code</th>
   <th>Shift Code</th>
   <th>Date</th>
   <th> Update</th>
   </tr>" ;
   while($row=mysql_fetch_assoc($result))
   {
   echo "<tr>";
   echo "<td>" . $row['ecode'] . "</td>";
   echo "<td>" . $row['edate'] . "</td>";
   echo "<td>" . $row['scode'] . "</td>";
   echo '<td> <a ref="empinsshf.php?ecode='.$row['ecode'].'">shift change</a> </td>  ' ;
   echo "</tr>";
   }
   mysql_close($con);
   ?>
   </body>
   </html>
<html>
    <?
    $con=mysql_connect("localhost","root","root");
    mysql_select_db("master");
    if($_POST['Submit'])
    {
    $ecode=$_POST['ecode'];
   $scode=$_POST['scode'];
    $edate=$_POST['edate'];
   }
   if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
   mysql_select_db("master", $con);
   $query="INSERT INTO emp_shift  VALUES  ('$ecode','$scode','$edate')";
   if (mysql_query($query,$con))
   {
   echo "record added!";
  
   }
   else
   {
   echo "something went wrong";
   }
   mysql_close($con)
  ?>
   <html>
       <head><title></title></head>
     <body bgcolor="E6E6FA">
     <form method="POST" action="<? echo $PHP_SELF;?>">
      <h3> <p align="center"> Company Detail </h3>   </p>
         <table align="center">
      <tr> <th> Code :</th><td> <input type="text" name="ecode" size="20" value = "<? echo $row['ecode']; ?>"></td></tr>
      <tr><th> Shift:</th><td>
    <select size="1" name="scode" value ="<? echo $row['scode']; ?>">
      <option>shifts</option>
      <option>morning1</option>
      <option>morning2</option>
      <option>eve1</option>
      <option>eve2</option>
   </select>
       </td></tr>
   <tr> <th> date :</th><td> <input type="text" name="edate" size="20" value = "<? echo $row['edate']; ?>"></td></tr>
   <input type="submit" value="SAVE"> </td> </table>
    </form>
    </body>
    </html>

Hi.

Can I have the mysql table structure with some sample data?

Thanks

hi.......

i solve my prob......... coding was correct bt the prob was in database structure...............

ok great and congracts,
mark this as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.