hello all. here is my code which searches all my record.

<?php
/**
 * Main.php
 */
include("include/session.php");
//include("viewproj.php");
?>
<html>
<head>
<title>Export to Excel</title>
</head>
<body>
<form action="searchemp.php" method="post" >
<?php
    define ('DB_NAME', 'vincegac_vince');
    define ('DB_USER', 'root');
    define ('DB_PASSWORD', '');
    define ('DB_HOST', 'localhost');
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!$db_selected) {
        die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
    }
    $UserName = $session->username;
    $strSQL = "SELECT * FROM employee WHERE projmgr = '$UserName' ";
    $rs = mysql_query($strSQL);

?>
<table border="1">

<tr>
    <th>Employee Number</th><th>First Name</th><th>Middle Name</th><th>Last Name</th><th>Home Address</th><th>Email Address</th>
    <th>Office/project number</th><th>Mobile number</th><th>Home number</th><th>Position</th><th>Practice</th>
    <th>Project Name</th><th>Project Manager</th><th>Team Leader</th>
</tr> 

<?php

    while($row = mysql_fetch_array($rs)) {

?>
<tr>

    <td><input name="emp_number" size="10" type="text" value="<?php echo $row['emp_number'] ?>" readonly="readonly"/></td>
    <td><input name="fname" size="10" type="text" value="<?php echo $row['fname'] ?>"/></td>
    <td><input name="mname" size="10" type="text" value="<?php echo $row['mname'] ?>"/></td>
    <td><input name="lname" size="10" type="text" value="<?php echo $row['lname'] ?>" /></td>
    <td><input name="homeadd" size="10" type="text" value="<?php echo $row['homeadd'] ?>" /></td>
    <td><input name="emailadd" size="10" type="text" value="<?php echo $row['emailadd'] ?>" /></td>
    <td><input name="ofcnum" size="10" type="text" value="<?php echo $row['ofcnum'] ?>" /></td>
    <td><input name="mobilenum" size="10" type="text" value="<?php echo $row['mobilenum'] ?>" /></td>
    <td><input name="homenum" size="10" type="text" value="<?php echo $row['homenum'] ?>" /></td>
    <td><input name="position" size="10" type="text" value="<?php echo $row['position'] ?>"/></td>
    <td><input name="practice" size="10" type="text" value="<?php echo $row['practice'] ?>" /></td>
    <td><input name="projname" size="10" type="text" value="<?php echo $row['projname'] ?>" readonly="readonly"/></td>
    <td><input name="projmgr" size="10" type="text" value="<?php echo $row['projmgr'] ?>" readonly="readonly"/></td>
    <td><input name="teamlead" size="10" type="text" value="<?php echo $row['teamlead'] ?>" /></td>
    <td><input type="submit" name="edit" value="Edit" onclick="this.form.action='update.php'"/></td>
    <td><input type="submit" name="del" value="Delete" onclick="this.form.action='delete.php'"/></td>


</tr>    

    <?php    
    } 
    ?>
    </table>
    <?php mysql_close(); ?>

    <p><a href="main.php"> Home</a> <a href="demo-form.php"> Add Member</a></p>

</form>

</body>
</html>

and here is my code for update

<?php

    define ('DB_NAME', 'vincegac_vince');
    define ('DB_USER', 'root');
    define ('DB_PASSWORD', '');
    define ('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
    $empnumber = $_POST["emp_number"];
    $fname = $_POST["fname"];
    $mname = $_POST["mname"];
    $lname = $_POST["lname"];
    $homeadd = $_POST["homeadd"];
    $emailadd = $_POST["emailadd"];
    $ofcnum = $_POST["ofcnum"];
    $mobilenum = $_POST["mobilenum"];
    $homenum = $_POST["homenum"];
    $position = $_POST["position"];
    $practice = $_POST["practice"];
    $projname = $_POST["projname"];
    $projmgr = $_POST["projmgr"];
    $teamlead = $_POST["teamlead"];

$sql = "UPDATE employee SET fname = '$fname', mname = '$mname', lname = '$lname', homeadd = '$homeadd', emailadd = '$emailadd', ofcnum = '$ofcnum', mobilenum = '$mobilenum', homenum = '$homenum', position = '$position', practice = '$practice', projname = '$projname', projmgr = '$projmgr', teamlead = '$teamlead'
        Where emp_number = '$empnumber'";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
    }
//echo '<p>One member added! <a href="demo-form.php">add another member</a></p>';
echo 'Record updated!';
echo '<p><a href="main.php">Home page</a></p><p><a href="searchemp.php">Back</a></p>';
mysql_close();

?>

i just want one row to be updated. how is that? :) Thanks you! :)

Recommended Answers

All 7 Replies

i just want one row to be updated.

What is the problem you're experiencing? The code to update only a single employee number is there already (assuming it's unique).

the code displays all my records, i just want to update 1 row.

Depends on how you want that to work. Common is to provide a link next to every row, that will take you to a detail page to update that row. That would mean you would have to add those links, and create a view-detail.php script, which you can then use to update a single record. Is that what you mean?

isnt it possible to just edit the record without having another form? what i want to happen is that, if the form displays all my records, i would be able to edit, lets say 2 records but one at a time but not having another form. i have an update button for every row.

Thanks!

Then you need an editable datagrid. It's possible, but you'd need to adjust your form. It needs to use arrays of inputs. Or use a tool like datatables.net which already offers part of that functionality.

Hi mallows u need to edit the data with in the same display grid right then u can go for the AJAX its simple to access using the ajax.
u need it as like it..
http://testfb.comuf.com/kirantt/kiran.html

please move the mouse pointer upon 2 and click on it and edit that

i think ur requirement also like this model...

Right

hello Mahesh57,

if this one is editted, will be saved in the database? :)

Thanks

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.