Hi all!!

i have here a code. What i want to happen is when i tick a radio button or checkbox, that will be the one displayed in the next form to be edited or deleted.

<html>
<head>
<title>Export to Excel</title>
</head>
<body>
<form 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 = $_POST["projname1"];
    $strSQL = "SELECT * FROM employee WHERE projname = '$UserName'"; //KONTI PA!
    $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_assoc($rs)) {
?>
<tr>
    <td><input name="emp_number" size="10" type="checkbox" value="" readonly="readonly"/><?php echo $row['emp_number'] ?></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>

</tr>    

<?php    
} 
?>
</table>
<input type="submit" name="edit" value="Edit" onclick="this.form.action='search.php'"/>
<input type="submit" name="del" value="Delete" onclick="this.form.action='delete.php'"/></td>     
<?php mysql_close(); ?>
<p><a href="index.php"> Home</a> <a href="demo-form.php"> Add Member</a></p>

</form>
</body>
</html>

I HOPE SOMEONE CAN HELP ME. Thanks! :)

Recommended Answers

All 5 Replies

Hi,

You can create two simple functions to catch all the form variables, and then call these functions on all pages designated for processing.

for example, if we need to catch name and last variables on submit.. we can simply create a function like this.

function check_form(&$form_var,$type){
    $form_var = array();
    if(isset ( $_POST[''.$type.''])){

    $form_var['fname'] = $_POST['fname'];
    $form_var['lname'] = $_POST['lname'];

    return true;
    }
    else{

    ## do whatever you need to do  here

    }

    }

The function above will grab form variables on submit. Of course, you can easily modify it to your application. Just change the submit to delete or edit.

Secondly, we can create a helper function to help the above function. This helper function will be responsible for populating the new form on edit, and presenting the items to be deleted on your delete query.

function return_data($form_var){

echo $form_var['fname'];
echo '<br/>';
echo $form_var['lname'];
echo '<br/>';


}

in your edit and delete page, just add

include_once('functions.php');

## call the function like this

if(check_form($form_var,'edit'))
return_data($form_var);

The echo on the second function is just for demonstration..We can easily modify it, for the database update or delete..

something like this ...

 function return_data($form_var){

     $form_var['fname'];
     $form_var['lname'];

     return $form_var;
}

we can call it this way

if(check_form($form_var,'edit'))
$submitted_data = return_data($form_var);

echo $submitted_data['fname'];
echo $submitted_data['lname'];

Or we can populate a new form ..!This form will be process for the second time to update your database.

<form method="post" action="">
<input type="text" name="fname" value="<?php echo $submitted_data['fname']?> />
<br/>
<input type="text" name="lname" value="<?php echo $submitted_data['lname']?> />
<br/>
<input type="submit" name="update"/>

if you want the first function to do the database update, you will just have to modify it and then write another function for the update or delete.

I hope you don't mind me asking. What does this comment mean?

//KONTI PA!

I don't mean it in a bad way, I normally write my comments on the top. It just caught my attention.

hi veedeoo,

dont mind that. hehe. its a filipino word which means, a bit more. :) anyways, can you help me with this?

cool, can you post your database structure, so that I can test it on my side. DO NOT include any personal information of the members, just the bare database.. My Father is part Irish/Italian/Filipino (The best combination for temper and Alcohol just kidding :), but the most handsome and nicest Dad I could ever wish for).

that's nice to know!! ok i'll send you my database. or if you want, i can send you the file itself so you can run and test it.

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.