i got 2 html pages with the following data

index.php (buttons: SAVE, EDIT)
update.php (buttons: UPDATE,DELETE)

Employee ID (primary key),
Employee Name (here i putting 2 buttons Edit,Save)

when i entered the empid and click the Edit button, the page has to go from index.php to update.php and at the same time it has to display the employee name w.r.t the empID

and i've written the code for update and delete buttons in update.php

my problem is i am not able to fill the textboxes in update.php w.r.t empid
and at the same time can't navigate to the update.php

please help me in this regard

Recommended Answers

All 7 Replies

i got 2 html pages with the following data

index.php (buttons: SAVE, EDIT)
update.php (buttons: UPDATE,DELETE)

Employee ID (primary key),
Employee Name (here i putting 2 buttons Edit,Save)

when i entered the empid and click the Edit button, the page has to go from index.php to update.php and at the same time it has to display the employee name w.r.t the empID

and i've written the code for update and delete buttons in update.php

my problem is i am not able to fill the textboxes in update.php w.r.t empid
and at the same time can't navigate to the update.php

please help me in this regard

Post your index.php and update.php code

THIS IS MY INDEX.PHP

<html>
<head>
<title>Sample PHP APP</title>
<script language="javascript">
function onsave()
{
    document.home.action="index.php";
    document.home.submit();
}
    function onedit()
    {
        document.home.action="index1.php";
        document.home.submit();
    }
</script>
</head>
<body>
        <form  name="home" method="post">
         <table  class="tbl" align="center"  cellpadding="2" cellspacing="15px"  >
                <tr>
                    <td align="right">Associate ID*   <input type="text" name="Aidtxt"></td>
                    <td>
                    <td>
                        Associate Name*   <input align="right" type="text" name="Anametxt">
                    </td>
                <tr>
<td align="right"><input type="submit" value="Save" name="savbtn" onclick="return onsave();"></td>
<td align="left"><input type="submit" value="Edit" name="edtbtn" onclick=" return onedit();">
</tr>
</table>
</form>
</body>
</html>
<?php
    include("conf/conf.php");
    $dbConf = new aphpConf();
    $databaseURL = $dbConf->get_databaseURL();
    $databaseUName = $dbConf->get_databaseUName();
    $databasePWord = $dbConf->get_databasePWord();
    $databaseName = $dbConf->get_databaseName();
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");
    $insert = "INSERT INTO Employeeinfo (AID,ANAME,DESG,FNAME,DoJ,MBNUM,EMAIL)
    Values ('$_POST[Aidtxt]','$_POST[Anametxt]','$_POST[Desigtxt]','$_POST[Fnametxt]',
    '$_POST[DoJtxt]','$_POST[Mbnumtxt]','$_POST[Emailtxt]')";
    if (!mysql_query($insert,$connection))
            {
        die ('Error: '.mysql_error());
        }
        echo "1 record added";
    mysql_close($connection)
?>

:icon_confused:AND THIS IS UPDATE.PHP:icon_cry:
<html>
    <head>  </head>
    <body>
        <form action="update.php" method="post">            
<table  class="tbl" align="center"  cellpadding="2" cellspacing="15px"  >
<tr>
     <td align="right">
    Associate ID   <input type="text" name="Aidtxt" value="<?PHP echo $_POST["Aidtxt"]; ?>">   </td>
  <td align="right">
  Associate Name   <input type="text" name="Anametxt" >              </td>
</tr>
 <tr>
<td align="right"><input type=submit value="Update" name="Updatetxt"></td>
<td align="left"><button  value="Cancel" onclick="location='http://172.16.5.56/appphp/index.php';">Cancel</button></td>
 </tr>
</table>
 </form>
    </body>
</html>
<?php
include("conf/conf.php");
    $dbConf = new aphpConf();
    $databaseURL = $dbConf->get_databaseURL();
    $databaseUName = $dbConf->get_databaseUName();
    $databasePWord = $dbConf->get_databasePWord();
    $databaseName = $dbConf->get_databaseName();
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");
mysql_query("UPDATE Employeeinfo SET ANAME='$_POST[Anametxt]',DESG='$_POST[Desigtxt]',FNAME='$_POST[Fnametxt]',DoJ='$_POST[DoJtxt]',
    MBNUM='$_POST[Mbnumtxt]',EMAIL='$_POST[Emailtxt]' WHERE AID='$_POST[Aidtxt]'");
    mysql_close($connection);
?>

I had seperate configuration file from where i can retrieve the database information and also

The first problem is
when i enter the associate/Employee id in index.php, w.r.t to that id , the data has to be retrieved from database to update.php.
and the second one is
i want to display a warn message box if the employee id entered by user in index.php is not there in database

no reply !@?

kindly anyone tell me how to overcome the above problem
and also can u give me link on how to implement gridview control of .net in php

please, please i really have to finish my project

no reply !@?

kindly anyone tell me how to overcome the above problem
and also can u give me link on how to implement gridview control of .net in php

please, please i really have to finish my project

Please use the code tags in future posts to enclose your code in. :)

Now, in your javascript in index.php, you have:

function onedit()
{
document.home.action="index1.php";
document.home.submit();
}

Shouldn't that be set to update.php?

Please use the code tags in future posts to enclose your code in. :)

You can say that again!

To check for a valid AID, try querying for all records with that id and then counting the number of rows returned:

$result = mysql_query("SELECT AID FROM Employeeinfo WHERE AID='".mysql_real_escape_string($aid)."' LIMIT 1");
if(mysql_num_rows($result)==1)
  //Valid AID
else
  //Invalid AID

The problem regarding the empty textboxes has to do with the fact that their respective values can't be found in POST (unless you passed them to the page through a POST Form). You need to query the Database for their values and insert them instead.

Thanks for your help!:)
I solved the problem,

but i am new to php&mysql that's why i am little bit confused in retrieving from database,

Thanks for your help! :)
I solved the problem,

but i am new to php&mysql that's why i am little bit confused in retrieving from database,

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.