I'm new to the php. I have created a update form as follows. I need to update the following fields.
Category,Short Description,Full Description. It's happening partially i.e, If I update only category field then remaining fields will go blank. So how to do it? Any help would be appreciated. Step 1. In view.php when the user click on Edit button it will go to the updateview.php.
Step 2. In updateview.php when the user changes any field value and press the update button it will go to the update.php
Step 3. From update.php it will return back to the view.php with updated value.
Thanks
View.php
<table id="example" class="row-border" cellspacing="0" width="100%">
<thead>
<tr>
<th>SRN</th>
<th>Client</th>
<th>Category</th>
<th>Short Description</th>
<th>Full Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($selectQ)){ ?>
<tr>
<td><?php echo $row['srn'];?></td>
<td><?php echo $row['client'];?></td>
<td><?php echo $row['category'];?></td>
<td><?php echo $row['sd'];?></td>
<td><?php echo $row['fd'];?></td>
<td><a href="updateview.php?srn=<?php echo $row['srn']; ?>" target="_blank">Edit</a></td>
</tr>
<?php } ?>
</tbody>
</table>
dbconn.php
<?php
$username = "root";
$password = "root";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("eservice",$dbhandle)
or die("Could not select database");
?>
updateview.php
<!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>
<div id="main-content">
<fieldset>
<?php
if(isset($_SESSION['example']))
{
echo $_SESSION['example'];
}
else
{
echo "Session destroyed..";
}
?>
</div>
<?php
include_once('dbconn.php');
$srn = $_GET['srn'];
$selQ = "Select * from main where srn = '".$srn."'";
$selectQ = mysql_query($selQ);
?>
<?php
while($row = mysql_fetch_array($selectQ)){ ?>
<form action="update.php" method="post" enctype="multipart/form-data" novalidate>
<div class="item">
<label> <span>SRN</span>
<input name="srn" type="text" id="srn" size="15" readonly="readonly" maxlength="40" value="<?php echo $row['srn']; ?>"/>
</label>
</div>
<div class="item">
<label> <span>Client</span>
<select class="required" name="client" value="<?php echo $row['client']; ?>" disabled="disabled"/>
<?php include_once('dbconn.php'); ?>
<option value=""><?php echo $row['client']; ?></option>
<?php
mysql_connect ("localhost","root","");
mysql_select_db ("eservice");
$select="eservice";
if (isset ($select)&&$select!="")
{
$select=$_POST ['NEW'];
}
?>
<?php
$list=mysql_query("select * from client");
while($row_list=mysql_fetch_assoc($list))
{
?>
<?php $ct = $row_list['cname'];?>
<option value="<?php echo $ct; ?>"<?php if($ct==$select){ echo "selected"; } ?> > <?php echo $ct; ?></option>
<?php } ?>
</select>
<input type="hidden" name="client" value = "<?php echo $row['client']; ?>" />
</label>
</div>
<div class="item">
<label> <span>Category</span>
<select class="required" name="category" value="<?php echo $row['category']; ?>"/>
<?php include_once('dbconn.php'); ?>
<option value=""><?php echo $row['category']; ?></option>
<?php
mysql_connect ("localhost","root","");
mysql_select_db ("eservice");
$select="eservice";
if (isset ($select)&&$select!="")
{
$select=$_POST ['NEW'];
}
?>
<?php
$list=mysql_query("select * from category");
while($row_list=mysql_fetch_assoc($list))
}
?>
<?php $ct = $row_list['name'];?>
<option value="<?php echo $ct; ?>"<?php if($ct==$select){ echo "selected"; } ?> > <?php echo $ct; ?></option>
<?php } ?>
</select>
</label>
</div>
<div class="item">
<label> <span>Short Description</span>
<textarea required="required" name='sd'><?php echo $row['sd']; ?></textarea>
</div>
<div class="item">
<label> <span>Full Description</span>
<textarea required="required" name='fd'><?php echo $row['fd']; ?></textarea>
</div>
<div class="item">
<button id='cancel' type='cancel'>Cancel</button>
<button id='send' type='submit'>Update</button>
</div>
</form>
<?php } ?>
update.php
<?php
include_once('dbconn.php');
$srn = $_POST['srn'];
$client = $_POST['client']; //required
$cate = $_POST['category'];
$sd = $_POST['sd']; //required
$fd = $_POST['fd']; //required
$updQry = "Update main Set client = '".$client."',category = '".$cate."',sd= '".$sd."',fd= '".$fd."' where srn = '".$srn."'";
$updateQ = mysql_query($updQry);
header("Location: view.php?res=U");
?>