hi everyone

i m completely fed up to solve dis prob.... i checked my code so many times but i cant find where is my mistake......
plz help me out.....................
I am selecting records from diff tables......my select query is correct and after dat m inserted new record and dat record display on the screen as well as stored in database ...... everything done correct. but i dont want my dropdown values predefined into my html code. i want to get dat value from database table.... and this is the problem which m facing nd failed to find solution.. i tried so many codes but no worked
if i use javascript function den dat will also work predefined ..... is there any function in js to do it...... or something else


CREATE TABLE shift_master (
scode varchar(15) NOT NULL default '',
tin time NOT NULL default '00:00:00',
tout time NOT NULL default '00:00:00',
des varchar(15) NOT NULL default '',
FULLTEXT KEY scode (scode),
FULLTEXT KEY scode_2 (scode),
FULLTEXT KEY scode_3 (scode)
) TYPE=MyISAM;

CREATE TABLE emp_shift (
ecode varchar(15) NOT NULL default '',
edate varchar(15) NOT NULL default '',
scode varchar(15) NOT NULL default ''
) TYPE=MyISAM;

CREATE TABLE emp_company (
ecode varchar(15) NOT NULL default '',
ename varchar(15) NOT NULL default '',
ecom varchar(15) NOT NULL default '',
edoj date NOT NULL default '0000-00-00',
edol date NOT NULL default '0000-00-00',
edpt varchar(15) NOT NULL default '',
esubdpt varchar(15) NOT NULL default '',
eesicode varchar(15) NOT NULL default '',
epf varchar(17) NOT NULL default '',
ecardno varchar(15) NOT NULL default '',
ebank int(15) NOT NULL default '0',
PRIMARY KEY (ecode)
) TYPE=MyISAM;

<?
mysql_connect("localhost","root","root");
mysql_select_db("master");

if($_POST['Submit'])
{
$ecode=$_POST['ecode'];
$edate=$_POST['edate'];
$scode=$_POST['scode'];
mysql_query("INSERT INTO emp_shift VALUES ('$ecode', '$edate', '$scode')");
header("location:empselectshf.php");
exit;
}
$ecode=$_GET['ecode'];
$result=mysql_query("select * from emp_shift where ecode='$ecode'");
$row=mysql_fetch_assoc($result);
  mysql_close() ;

?>


<html>
<body bgcolor=E6E6FA>

<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<h3> <p align="center"> <font color="160981"> Shift </font></p></h3>
 <table align="center"  >
<tr> <th>Employee  Code  </th> <td>
<input name="ecode" type="text" id="ecode" value="<? echo $row['ecode']; ?>"/>     </td> </tr>
<tr> <th> Date </th>  <td>
<input name="edate" type="text" id="edate" value="<? echo $row['edate']; ?>"/> </td></tr>

<tr> <th> Shift :   </th> <td>
  <select size="1" name="scode">
   <option>morning1</option>
   <option>morning2</option>
   <option>Afternoon        </option>
   <option>Afternoon1</option>
   </select> </td> </tr>

<tr> <td> <td> <td> <input type="submit" name="Submit" value="Change" /> </td> </tr>
</table>
</form>
</body>
</html>
<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);
$query=mysql_query("SELECT emp_company.ecode, emp_shift.edate ,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>Date</th>
<th>Shift Code</th>
<th> Update</th>
</tr>" ;
while($row=mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td>" . $row['ecode'] . "</td>";
echo "<td>" . $row['edate'] . "</td>";
echo "<td>" . $row['scode'] . "</td>";

echo '<td> <a href="empupshf.php?ecode='.$row['ecode'].' "> change Shift </a> </td>' ;
echo "</tr>";
}
mysql_close($con);
?>
</body>
</html>

i found a couple error with in you document as you were using echo instead of print also you are using <? opening tag when you should be using <?php and the rest you can compare my versions compared to your own

here's page one

<?php
mysql_connect("localhost","root","root");
mysql_select_db("master");

if($_POST['Submit']){
	$ecode=$_POST['ecode'];
	$edate=$_POST['edate'];
	$scode=$_POST['scode'];
	mysql_query("INSERT INTO emp_shift VALUES ('$ecode', '$edate', '$scode')");
	header("location:empselectshf.php");
	exit;
}
$ecode=$_GET['ecode'];
$result=mysql_query("select * from emp_shift where ecode='$ecode'");
$row=mysql_fetch_assoc($result);
mysql_close() ;

?>

<html>
<body bgcolor=E6E6FA>

<form id="form1" name="form1" method="post">
<h3> <p align="center"> <font color="160981"> Shift </font></p></h3>
 <table align="center"  >
<tr> <th>Employee  Code  </th> <td>
<input name="ecode" type="text" id="ecode" value="<?php print($row['ecode']); ?>"/>     </td> </tr>
<tr> <th> Date </th>  <td>
<input name="edate" type="text" id="edate" value="<?php print($row['edate']); ?>"/> </td></tr>

<tr><th>Shift :   </th><td>
  <select size="1" name="scode">
   <option>morning1</option>
   <option>morning2</option>
   <option>Afternoon</option>
   <option>Afternoon1</option>
   </select></td></tr>

<tr><td><td><td> <input type="submit" name="Submit" value="Change" /></td></tr>
</table>
</form>
</body>
</html>

and here is page two

<html>
<body bgcolor="E6E6FA">
<!--<h3><p align="center">Shift Updation Table</p></h3>!-->
<?php
$con=mysql_connect("localhost","root","root") or die('Could not connect: '.mysql_error());
mysql_select_db("master", $con);
$query=mysql_query("SELECT emp_company.ecode, emp_shift.edate ,emp_shift.scode FROM emp_company, emp_shift where emp_company.ecode=emp_shift.ecode");
print "<table border='1'><caption>Employee 's Record Updation Table</caption><BR><BR><BR><BR>\n<tr>\n<th>Empoyee Code</th>\n<th>Date</th>\n<th>Shift Code</th>\n<th>Update</th>\n</tr>";
while($row=mysql_fetch_array($query)) {
	print '<tr>';
	print '<td>'.$row['ecode'].'</td>';
	print '<td>'.$row['edate'].'</td>';
	print '<td>'.$row['scode'].'</td>';
	print '<td> <a href="empupshf.php?ecode='.$row['ecode'].'">change Shift</a></td>';
	print '</tr>';
}
mysql_close($con);
?>
</body>
</html>

let me know how they work if not i can improve them for you since they only took a couple sec's so hope this helps

hi jcanaway
thanx for your help.... but my prob still there ......
<select size="1" name="scode">
<option>morning1</option>
<option>morning2</option>
<option>Afternoon </option>
<option>Afternoon1</option>
</select>
i want these values from my database not like this predefined..... waiting for your reply

ok then how do you want to populate it then like with a little bit of ajax and a dash of php because you can use jquery to solve this problem i think i understand what you want but still not enough information on how you would like it done so we can help I've done something how it seems that your explaining so far with in my sign up form in my website using ajax but its a little hard to explain but you give me some more information and ill help you with you problem but you can check out some website that might help you and there listed below

http://jquery.com
http://developphp.com
http://php.net
http://www.w3schools.com/

so check them out and see if they'll help you out at all

hi jcanaway
thaxxxxxxxxx alot for your help....... i got my error now i m succesfuly populate dropdown from database......... the mistake was only dat i was not established connection within my html code in empselectshf file............... now Cheerzzzzzzzz..

alright that's good to hear maybe next time i can be a little more helpful

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.