[SOLVED] Going Nuts! qry update aint working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

[SOLVED] Going Nuts! qry update aint working?

Post by abshaw »

following is the complete code of my "test.php" doc. what i want to see happen is that the user selects the yes option and then inputs the date from the icon next to it.

Once the input is selected and the update is done, it shows the recently inputed values. and then doesnt give the user the option to enter it again.

kind of a write once module. Help!

Code: Select all

<?php
include ("opendatabase.php");
$ur_file_id=5;
//start of claim update

if ( $pageaction == "clmupdate") {
 $update_status = ", Claim Information updated" ; 
 $query="update claims SET q1=".$updt_q1.", q2=".$updt_q2.", q3=".$updt_q3.", q4=".$updt_q4.",	q4a=".$updt_q4a.", 
			q1_date=".$updt_q1_date.", q2_date=".$updt_q2_date.", q3_date=".$updt_q3_date.", q4_date=".$updt_q4_date."      
		WHERE ur_file_id=".$urfile ; 
$result = mysql_query($query);
 
  }

//end of claim update

//start of normal page rendering.
$query = "select * from claims where ur_adjuster_no =4 and ur_file_id=5" ;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
// now assign the questionaire fields to temp variables for proper visual coding.
$page_q1 = $row['q1'];
$page_q2 = $row['q2'];
$page_q3 = $row['q3'];
$page_q4 = $row['q4'];
$page_q4a = $row['q4a'];

$page_q1_date = $row['q1_date'];
$page_q2_date = $row['q2_date'];
$page_q3_date = $row['q3_date'];
$page_q4_date = $row['q4_date'];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Universal Risk Claims Detail Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style3 {color: #FFFFFF}
.style4 {font-size: 24px}
.style5 {font-size: 36px}
.style6 {font-size: 18px}
body {
	margin-left: 0px;
	margin-top: 1px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style7 {
	color: #006666;
	font-size: 24px;
}
.style8 {font-size: 12px}

input 
{
border: 1px solid #000000;
background: #DDDDDD;
}
select
{
border: 1px solid #000000;
background: #DDDDDD;
font-family: verdana,helvetica,arial,sans-serif;
font-size: 10px;
}

-->
</style>

<script language="JavaScript" src="calendar1.js"></script>
</head>

<body>

<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="10" rowspan="6" align="left" valign="top">&nbsp;</td>
    <td width="25" rowspan="6" align="left" valign="top" bgcolor="#9E0B0E">&nbsp;</td>
    <td width="5" rowspan="6" align="left" valign="top">&nbsp;</td>
    <td width="730" bgcolor="#006666"><span class="style3">&nbsp;&nbsp;<span class="style4">Status System</span> </span></td>
    <td width="5" rowspan="6" align="left" valign="top">&nbsp;</td>
    <td width="25" rowspan="6" align="left" valign="top" bgcolor="#9E0B0E">&nbsp;</td>
  </tr>
  <tr>
    <td height="2" align="left" valign="top"></td>
  </tr>
  <tr>
    <td width="730" align="center" valign="top" bgcolor="#9E0B0E"><div align="center" class="style3 style6">Claim Detail Page <? echo $update_status ; ?> </div></td>
  </tr>
  <tr>
    <td height="15" align="left" valign="top"></td>
  </tr>
  <tr>
    <td height="20" align="left" valign="top"><table width="730" border="0" cellspacing="0" cellpadding="0">
      <tr align="left" valign="top">
        <td colspan="6"><div align="left">        </div></td>
        </tr>
      <tr>
        <td class="style8">Claim Assignment Type </td>
        <td colspan="3" align="left" valign="top"><span class="style8"><? echo $row['claim_assignment_type'] ;?></span></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
	  <tr>
        <td colspan="6">&nbsp;</td>
        </tr>
	  <tr align="left" valign="top">
	    <td height="100" colspan="6">
		<form name="adjdetail" action="test.php" method="post">
		<table width="730" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="25" align="left" valign="top" class="style8">1.</td>
            <td width="340" align="left" valign="top" class="style8"> Has initial contact been made with the insured? </td>
            <td width="10" align="left" valign="top">&nbsp;</td>
            <td width="100" align="left" valign="top"><span class="style8"><? if ($page_q1_date == 0) {?><input type="radio" name="updt_q1" value="NO" checked>NO<input type="radio" name="updt_q1" value="YES">Yes<? } else { echo $page_q1; ?><input type="hidden" name="$updt_q1" value="<? echo $page_q1; ?>"><?  } ?></span></td>
            <td width="30" align="right" valign="top" class="style8">Date:&nbsp;&nbsp; </td>
            <td width="150" align="left" valign="top" class="style8"><? if ($page_q1_date == 0) {?><input type="text" name="updt_q1_date" value="" size="10">&nbsp;&nbsp;<a href="javascript:cal1.popup();"><img src="../images/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><? } else {echo $page_q1_date ; ?><input type="hidden" name="updt_q1_date" value="<? echo $page_q1_date ; ?>"><?  } ?></td>
            <td width="75" align="left" valign="top">&nbsp;</td>
          </tr>
          <tr>
            <td class="style8">2.</td>
            <td class="style8"> If No, contact attempted? </td>
            <td>&nbsp;</td>
            <td><span class="style8"><? if ($page_q2_date == 0) {?><input type="radio" name="updt_q2" value="NO" checked>NO<input type="radio" name="updt_q2" value="YES">Yes<? } else { echo $page_q2; ?><input type="hidden" name="$updt_q2" value="<? echo $page_q2; ?>"><?  } ?></span></td>
            <td align="right" valign="top"><span class="style8">Date:&nbsp;&nbsp;</span></td>
            <td align="left" valign="top"><span class="style8"><? if ($page_q2_date == 0) {?><input type="text" name="updt_q2_date" value="" size="10">&nbsp;&nbsp;<a href="javascript:cal2.popup();"><img src="../images/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><? } else {echo $page_q2_date ; ?><input type="hidden" name="updt_q2_date" value="<? echo $page_q2_date ; ?>"><?  } ?></span></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="style8">3.</td>
            <td class="style8"> Inspected/Scoped ? </td>
            <td>&nbsp;</td>
            <td><span class="style8"><? if ($page_q3_date == 0) {?><input type="radio" name="updt_q3" value="NO" checked>NO<input type="radio" name="updt_q3" value="YES">Yes<? } else { echo $page_q3; ?><input type="hidden" name="$updt_q3" value="<? echo $page_q3; ?>"><?  } ?></span></td>
            <td align="right" valign="top"><span class="style8">Date:&nbsp;&nbsp;</span></td>
            <td align="left" valign="top"><span class="style8"><? if ($page_q3_date == 0) {?><input type="text" name="updt_q3_date" value="" size="10">&nbsp;&nbsp;<a href="javascript:cal3.popup();"><img src="../images/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><? } else {echo $page_q3_date ; ?><input type="hidden" name="updt_q3_date" value="<? echo $page_q3_date ; ?>"><?  } ?></span></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="style8">4.</td>
            <td class="style8"> Has a reserve change been entered in the system? </td>
            <td>&nbsp;</td>
            <td><span class="style8"><? if ($page_q4_date == 0) {?><input type="radio" name="updt_q4" value="NO" checked>NO<input type="radio" name="updt_q4" value="YES">Yes<? } else { echo $page_q4; ?><input type="hidden" name="$updt_q4" value="<? echo $page_q4; ?>"><?  } ?></span></td>
            <td align="right" valign="top"><span class="style8">Date:&nbsp;&nbsp;</span></td>
            <td align="left" valign="top"><span class="style8"><? if ($page_q4_date == 0) {?><input type="text" name="updt_q4_date" value="" size="10">&nbsp;&nbsp;<a href="javascript:cal4.popup();"><img src="../images/img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><? } else {echo $page_q4_date ; ?><input type="hidden" name="updt_q4_date" value="<? echo $page_q4_date ; ?>"><?  } ?></span></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td class="style8">&nbsp;&nbsp;&nbsp;4-a. Reserve Amount</td>
            <td>&nbsp;</td>
            <td><span class="style8"><? if ($page_q4a == 0) {?>$ &nbsp;<input type="text" name="updt_q4a" value="0" size="10"><? } else { ?>$ &nbsp;<? echo $page_q4a; ?><input type="hidden" name="$updt_q4a" value="<? echo $page_q4a; ?>"><?  } ?></span></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="style8">&nbsp;</td>
            <td height="20" align="left" valign="top" class="style8">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="style8">&nbsp;</td>
            <td height="20" align="left" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="submit" name="Submit" value="Update Claim">
			  <input type="hidden" name="pageaction" value="clmupdate">
			  <input type="hidden" name="PHPSESSID" value="<? echo $PHPSESSID ; ?>">
			  <input type="hidden" name="ur_adj_id" value="<? echo $ur_adj_id ; ?>">
              <input type="hidden" name="urfile" value="<? echo $urfile ; ?>">
			  </td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
		</form>
		
		</td>
	    </tr>
	  <tr>
	    <td colspan="6" align="left" valign="top">&nbsp;</td>
		<td height="10">&nbsp;</td>
	    </tr>
    </table>	</td>
  </tr>
  <tr>
    <td align="center" valign="top"><div align="center">
        <p>&nbsp;</p>
    </div></td>
  </tr>
</table>
</body>
</html>
<?
}# end of while statement
?>	
<script language="JavaScript">
			<!-- // create calendar object(s) just after form tag closed
				 // specify form element as the only parameter (document.forms['formname'].elements['inputname']);
				 // note: you can have as many calendar objects as you need for your application
				var cal1 = new calendar1(document.forms['adjdetail'].elements['updt_q1_date']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['adjdetail'].elements['updt_q2_date']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
				var cal3 = new calendar1(document.forms['adjdetail'].elements['updt_q3_date']);
				cal3.year_scroll = true;
				cal3.time_comp = false;
				var cal4 = new calendar1(document.forms['adjdetail'].elements['updt_q4_date']);
				cal4.year_scroll = true;
				cal4.time_comp = false;
				var cal5 = new calendar1(document.forms['adjdetail'].elements['updt_q5_date']);
				cal5.year_scroll = true;
				cal5.time_comp = false;
				var cal6 = new calendar1(document.forms['adjdetail'].elements['updt_q6_date']);
				cal6.year_scroll = true;
				cal6.time_comp = false;
				var cal7 = new calendar1(document.forms['adjdetail'].elements['updt_q7_date']);
				cal7.year_scroll = true;
				cal7.time_comp = false;
				var cal8 = new calendar1(document.forms['adjdetail'].elements['updt_q8_date']);
				cal8.year_scroll = true;
				cal8.time_comp = false;
				var cal9 = new calendar1(document.forms['adjdetail'].elements['updt_q9_date']);
				cal9.year_scroll = true;
				cal9.time_comp = false;
				var cal10 = new calendar1(document.forms['adjdetail'].elements['updt_q10_date']);
				cal10.year_scroll = true;
				cal10.time_comp = false;
				var cal11 = new calendar1(document.forms['adjdetail'].elements['updt_q11_date']);
				cal11.year_scroll = true;
				cal11.time_comp = false;
				var cal12 = new calendar1(document.forms['adjdetail'].elements['updt_q12_date']);
				cal12.year_scroll = true;
				cal12.time_comp = false;
				var cal13 = new calendar1(document.forms['adjdetail'].elements['updt_q13_date']);
				cal13.year_scroll = true;
				cal13.time_comp = false;
				var cal14 = new calendar1(document.forms['adjdetail'].elements['updt_q14_date']);
				cal14.year_scroll = true;
				cal14.time_comp = false;		
			</script>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

First of all, your script requires register globals to be ON, and by default it is set to off.

Secondly, what exackly is wrong with the script? What is being outputted? Where does it fail?
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

the actual script in play could be seen at

http://www.universalrisk.com/php/test.php
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Never answered my questions.


Try changing register globals to OFF.
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

the thing wrong with the script is that when i input the values, they never get into the database. thus update qry not working.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well take a look when you echo out the following

Code: Select all

echo "update claims SET q1=".$updt_q1.", q2=".$updt_q2.", q3=".$updt_q3.", q4=".$updt_q4.",    q4a=".$updt_q4a.", q1_date=".$updt_q1_date.", q2_date=".$updt_q2_date.", q3_date=".$updt_q3_date.", q4_date=".$updt_q4_date."      
        WHERE ur_file_id=".$urfile;
You see ?
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

when i entered the echo line, this is the result that is displayed on the page (i only ented the firt line).

update claims SET q1=YES, q2=NO, q3=NO, q4=NO, q4a=0, q1_date=2005-03-02, q2_date=, q3_date=, q4_date= WHERE ur_file_id=5

this can be seen in action at

http://www.universalrisk.com/php/test.php
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

hey fyed

the or die thing worked, as it told me that the syntax is incorrect so i changed the query "quotation marks" sturcture and it works (partially)


Code: Select all

$query=&quote;update claims SET q1='$updt_q1', q2='$updt_q2', q3='$updt_q3', q4='$updt_q4', q4a='$updt_q4a', 
			q1_date='$updt_q1_date', q2_date='$updt_q2_date', q3_date='$updt_q3_date', q4_date='$updt_q4_date'      
		WHERE ur_file_id='$urfile'&quote; ;



now the thing that is not working ,

once i have inputed a value, i want to db to retain the value of that field and for the user to not be able to change any value, but if i keep on hitting the submitt button, it deletes the "yes / no" answer :cry:
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

the input tags are not retaining their values

once i have updated the values, the values go into the db perfectly and then, are displayed appropriatly. but if the update is hit again with the remaining data it erases the previous data.

what can be done.?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Fingerprint the form so it can only be used once (pass a hidden field containing a unique code that is stored on user's session and consequently deleted), or maybe simpler only output form/submit tags the first time, and not the second. To redisplay values but in a way you wish to avoid a form submission, you can simply use an alternate page which doesn't require a form to be built...
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post by abshaw »

got it done.

it was a stupid mistake (daa)

in my <input> tags the name i was declaring was $var_name instead of var_name. as soon as i removed the $ form the name, it worked like a charm.

thankyou all for the support. cheers.
Post Reply