Hi all,

This is regarding part of my project. There is a junior staff member who adds data to the database by way of a form.(customer details) Thereafter a supervisor should logged into the system and if he needs he should be able to modify the details entered by junior staff member.

This is the code regarding retrieval and modification of data.

<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv4 {
	position:absolute;
	width:776px;
	height:433px;
	z-index:3;
	left: 182px;
	top: 279px;
}
#form1 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

[B][B]/*<?php

$nic =$_POST['nic'];
$full_name=$_POST['full_name'];
$name_with_initials=$_POST['name_with_initials'];
$address=$_POST['address'];
$contact_number=$_POST['contact_number'];
$gender=$_POST['gender'];

$result = mysql_query("UPDATE `customer` SET `nic` = '$nic', `full_name` = '$full_name', `name_with_initials` = $name_with_initials', address                       = '$address', contact_number = '$contact_number', gender  = '$gender'   WHERE `customer_id` = '$customer_id' ");
if($result)
echo "Your information has been successfully added to the database.";
else
echo "Failed";
?>*/[/B][/B]

<div id="apDiv4">

  <form action="" method="post" name="form1" id="form1">
    <fieldset>
      <legend class="cap"> Customer Details</legend>
      <table width="83%" border="0" cellspacing="0" cellpadding="5" align="center">
      <?php

           $query = "select * from customer";
           $result = mysql_query($query) or die(mysql_error());
           while ($row=mysql_fetch_array($result)){
			   
	  ?>
        <tr>
          <td>&nbsp;</td>
          <td class="title02">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%" height="35">&nbsp;</td>
          <td width="43%" class="title02" align="left">National ID</td>
          <td width="53%" class="attribute1" align="left"><input type="text" name="nic" size="30" class="attribute1" value=<?php echo $row['nic'];?>></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td height="33">&nbsp;</td>
          <td width="43%" class="title02" align="left">Full Name</td>
          <td width="53%" class="attribute1" align="left"><input type="text" name="full_name" size="50" class="attribute1" value=<?php echo $row['full_name']?>></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td height="34">&nbsp;</td>
          <td class="title02" align="left">Name With Initials</td>
          <td class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value=<?php echo $row['name_with_initials']?>></td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="43%" class="title02" align="left">Address</td>
          <td width="53%" class="attribute1" align="left"><label>
            <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea>
          </label></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="43%" class="title02" align="left">Contact Number</td>
          <td width="53%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value=<?php echo $row['contact_number']?>></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="43%" class="title02" align="left">Sex</td>
          <td width="53%" class="attribute1" align="left"><p>
            <select name="gender" id="jumpMenu" >
              <option selected="selected"><?php echo $row['gender']; ?></option>
              <option>Male</option>
              <option>Female</option>
            </select>
            <br />
          </p></td>
          <td width="2%">&nbsp;</td>
        </tr>
      </table>
      <p align="center">&nbsp;</p>
      <p align="center">
        <label>
          <input name="button" type="submit" onclick="return Validate();" id="button"  value="Modify Details"  />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label> <a href="accofficer_help.php">
          <input name="button" type="submit"  id="button"   value="Help"  />
        </a></label>
        </td>
      </p>
    </fieldset>
    <td width="5%">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><font color="red" size="1" ></font></td>
      <td>&nbsp;</td>
    </tr>
     <?php
		   }
		   ?>
    </table>
  </form>
</div>
<p>&nbsp;</p>
</body>
</html>

The code marked inside /* and */ is the modification code which is not working.Anyone one can give me the correct coding?

Thanks,
Heshan.

You have to set $customer_id; it's NULL in here :)
If you wanna post it via the form; just insert the next hidden field in the form:

<input type="hidden" name="customer_id" value="<?php echo $row['customer_id'];" />

You said that this is how it should be changed.

$result = mysql_query("UPDATE customer SET `customer_id` = '$customer_id', `nic` = '$nic', `full_name` = '$full_name', `name_with_initials` =                      $name_with_initials', address = '$address', contact_number = '$contact_number', gender  = '$gender'  WHERE `customer_id`                      = '$customer_id' ");

There are errors saying undefined index nic, full_name, name_with_initials etc.....

Thanks,
Heshan

no .. you don't set the customer_id (the primary key) in the DB! you just assign the VARIABLE $customer_id to a value (using my method).

Can you give me an example since i do not want it to be posted via the form like your code.....

customer_id is set as an auto increment value in my table.

There's no other way around the Hidden field to post ...

Hey,

What is the wrong with this code,

<?php

$customer_id = $_POST['customer_id'];
$nic =$_POST['nic'];
$full_name=$_POST['full_name'];
$name_with_initials=$_POST['name_with_initials'];
$address=$_POST['address'];
$contact_number=$_POST['contact_number'];
$gender=$_POST['gender'];

$result = mysql_query("UPDATE customer SET `nic` = '$nic', `full_name` = '$full_name', `name_with_initials` =                      $name_with_initials', address = '$address', contact_number = '$contact_number', gender  = '$gender'  WHERE `customer_id` =                       '$customer_id' ");
if($result)
echo "Your information has been successfully added to the database.";
else
echo "Failed";
?>

you forgot ' near $name_with_initials

<?php

$customer_id = $_POST['customer_id'];
$nic =$_POST['nic'];
$full_name=$_POST['full_name'];
$name_with_initials=$_POST['name_with_initials'];
$address=$_POST['address'];
$contact_number=$_POST['contact_number'];
$gender=$_POST['gender'];

$result = mysql_query("UPDATE customer SET `nic` = '$nic', `full_name` = '$full_name', `name_with_initials` = '$name_with_initials', address = '$address', contact_number = '$contact_number', gender  = '$gender'  WHERE `customer_id` = '$customer_id' ");
if($result)
echo "Your information has been successfully added to the database.";
else
echo "Failed";
?>

Things are ok. The update function has worked.But the thing is the supervisor wants to modify customer details if he needs.

You remember that space problem occurred earlier. As a result those fields cannot be updated(full name, name with initials and gender) because of the space problem. What can i do for that?

you checked for value="<?php .... ?>" ??

oops,I forgot to do that.Now everything is working fine. Thank you very much for your support Mindster....

If u would not mind can you please help me out in "Problem in generating account numbers based on account types" topic.It was already posted in the forum. I am struggling in this area..

Thanks,
Heshan

ok I'll see what I can do.
You can now 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.