PDA

View Full Version : update problem, urgent



purnendu2311
05-08-2007, 10:07 AM
Hi all,

i am getting problem in updation. i have requirment. if record is not there in database then insert the record otherwise update the record (if already record is there). It is inserting or updating fine but problem is that, after updation i need to represh (F5) the page to make the changes.

i want , i after preshing submit button, without refresh , i want the value should reflect into the form. I have writen select, insert, update command in one form.

Plz give the solution so that without fresh i fetch my data from database table.

This is my code::::::::::::::::::::::::::::


<?php
session_start();
include 'connection.php';


$sqry="select * from register_dtl where uname='".$_SESSION['username']."'";
$rs_sel=mysql_query($sqry) or die("error:". mysql_error());
$row_sel=mysql_fetch_assoc($rs_sel);
$no_of_rows_s=mysql_num_rows($rs_sel);
$sel_headline=$row_sel['headline'];
$sel_aboutme=$row_sel['about_me'];
$sel_liketo_meet=$row_sel['liketo_meet'];
$sel_interests=$row_sel['interests'];
$sel_music=$row_sel['music'];
$sel_movies=$row_sel['movies'];
$sel_television=$row_sel['television'];
$sel_books=$row_sel['books'];
$sel_heroes=$row_sel['heroes'];
if($no_of_rows_s ==0)
{
if(isset($_REQUEST['headline']) && $_REQUEST['headline']!="")
{
$headline=$_POST['headline'];
$about_me=$_POST['about_me'];
$liketo_meet=$_POST['liketo_meet'];
$interests=$_POST['interests'];
$music=$_POST['music'];
$movies=$_POST['movies'];
$television=$_POST['television'];
$books=$_POST['books'];
$heroes=$_POST['heroes'];

$qry_ins="insert into register_dtl(uname,headline,about_me,liketo_meet,interests,music,movies,television,books,heroes) values
('".$_SESSION['username']."','$headline','$about_me','$liketo_meet','$interests','$music','$movies','$television', '$books', '$heroes')";
$rs_ins=mysql_query($qry_ins) or die("error:". mysql_error());
}
}
else
{
if(isset($_REQUEST['headline']) && $_REQUEST['headline']!="")
{

$headline1=$_POST['headline'];
$about_me1=$_POST['about_me'];
$liketo_meet1=$_POST['liketo_meet'];
$interests1=$_POST['interests'];
$music1=$_POST['music'];
$movies1=$_POST['movies'];
$television1=$_POST['television'];
$books1=$_POST['books'];
$heroes1=$_POST['heroes'];

$update="update register_dtl set uname='".$_SESSION['username']."',
headline='$headline1',
about_me='$about_me1',
liketo_meet='$liketo_meet1',
interests='$interests1',
music='$music1',
movies='$movies1',
television='$television1',
books='$books1',
heroes='$heroes1'
where uname='".$_SESSION['username']."'";

$rs=mysql_query($update) or die("error:". mysql_error());

}
}
?>
<!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=iso-8859-1" />
<title>aifilia</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}

-->
</style>
</head>

<body >
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">


<tr>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><span class="formline">
<input name="headline" type="text" id="headline" size="60" value="<? echo $row_sel['headline'] ?>"/>
</span></td>

</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>About
me:</strong> </td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="about_me" cols="45" rows="12" id="about_me"><? echo $sel_aboutme ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>
<td height="0" bgcolor="#A3C5E0">&nbsp;</td>
<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>I'd
Like to meet:</strong> </td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="liketo_meet" cols="45" rows="12" id="liketo_meet"><? echo $sel_liketo_meet ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>Intreststs:</strong>
</td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="interests" cols="45" rows="5" id="interests"><? echo $sel_interests ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>
<td height="0" bgcolor="#A3C5E0">&nbsp;</td>
<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>Music:</strong>
</td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="music" cols="45" rows="5" id="nusic"><? echo $sel_music ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>movies:</strong>
</td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="movies" cols="45" rows="5" id="movies"><? echo $sel_movies ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>Television:</strong>
</td>
<td align="left" valign="top" bgcolor="#A3C5E0" class="blacktext">&nbsp;</td>
<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="television" cols="45" rows="5" id="television"><? echo $sel_television ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>Books:</strong>
</td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="books" cols="45" rows="5" id="books"><? echo $sel_books ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>

<tr>

<td height="25" align="right" valign="top" bgcolor="#A3C5E0" class="blacktext"><strong>Heroes:</strong>
</td>

<td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext"><textarea name="heroes" cols="45" rows="5" id="heroes"><? echo $sel_heroes ?></textarea></td>
<td bgcolor="#A3C5E0">&nbsp;</td>
</tr>
<tr>
<td height="45" align="center" bgcolor="#A3C5E0">&nbsp;</td>
<td height="45" colspan="3" align="center" valign="middle" bgcolor="#A3C5E0" class="blacktext"><input name="save" id="save" value="Save All " type="submit" onclick="save();">
<input name="reset" id="reset" value="cancel" type="reset" /></td>

</tr>

</form>
</table></td>

</tr>
</table></td>
</tr>



</td>
</table>
</body>
</html>

This is my databse table::::::::::


CREATE TABLE `register_dtl` (
`sno` int(15) NOT NULL auto_increment,
`uname` varchar(250) collate latin1_general_ci NOT NULL,
`headline` varchar(250) collate latin1_general_ci NOT NULL,
`about_me` text collate latin1_general_ci NOT NULL,
`liketo_meet` text collate latin1_general_ci NOT NULL,
`interests` text collate latin1_general_ci NOT NULL,
`music` text collate latin1_general_ci NOT NULL,
`movies` text collate latin1_general_ci NOT NULL,
`television` text collate latin1_general_ci NOT NULL,
`books` text collate latin1_general_ci NOT NULL,
`heroes` text collate latin1_general_ci NOT NULL,
PRIMARY KEY (`sno`),
UNIQUE KEY `uname` (`uname`)
)

Please help , it is urgent

Thanks & Regards

Ranjan