• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 90
  • Last Modified:

Record Not Updating

This table almost works.  Delete and Add are fine.  However: Update doesn't update.  I tried both checked and unchecked  Nothing happens.  The link.

http://www.davidschure.com/index.php

PHP
<?php
		  include("conn.php");
		  $mode=$_GET["mode"];
		  if($mode=="add") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="insert into $branch(recordSite,recordUser, recordPass) values('$recordSite','$recordUser','$recordPass')";
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: index.php");
			
		  } elseif($mode=="update") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="update $branch set recordSite='$recordSite',recordUser='$recordUser',recordPass='$recordPass' where recordId='$recordId'";
			//echo $sql;
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: index.php");
		  }
		  ?>

Open in new window


HTML
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td><hr size="1" noshade></td>
  </tr>
  <tr>
    <td>
      <form action="" method="post" name="" id="">
        <table width="600" border="1" align="center" cellpadding="2" cellspacing="2">
          <tr>
            <td><input name="topcheckbox" type="checkbox" class="check" id="topcheckbox" onClick="selectall();" value="ON">
Select All &nbsp;&nbsp;&nbsp;</td>
            <td colspan="3" align="center"><a href="form.php?mode=add">Add New Record </a></td>
          </tr>
          <tr>
            <td><strong><a href="javascript:goDel()">Delete</a></strong></td>
            <td><strong>Site</strong></td>
            <td><strong>User</strong></td>
            <td><strong>Pass</strong></td>
            <td><strong>Update</strong></td>
          </tr>
		  <?
		  include("conn.php");
		  $sql="select recordId,recordSite,recordUser,recordPass from $branch order by recordId";
		  $result=mysql_query($sql,$connection) or die(mysql_error());
		  while($row=mysql_fetch_array($result)) {
		  ?>
          <tr>
            <td><input name="<? echo $row['recordId']; ?>" type="checkbox" class="check"></td>
            <td><? echo $row['recordSite']; ?></td>
            <td><? echo $row['recordUser']; ?></td>
            <td><? echo $row['recordPass']; ?></td>
            <td><a href="<? echo "form.php?recordId=".$row['recordId']."&mode=update"; ?>">Update</a></td>
          </tr>
		  <? } ?>
        </table>
    </form></td>
  </tr>
</table>

Open in new window

0
DS928
Asked:
DS928
  • 8
  • 6
1 Solution
 
gr8gonzoConsultantCommented:
Try changing:
$mode=$_GET["mode"];
to:
$mode=$_REQUEST["mode"];

Your intermediate update form is using a POST method, which means that mode=update will be in $_POST["mode"], not $_GET["mode"]. The $_REQUEST variable is basically both $_GET and $_POST merged together, with $_POST values taking precedence.
0
 
DS928Author Commented:
Nope.  It didn't work.
0
 
gr8gonzoConsultantCommented:
Can you post all the code?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DS928Author Commented:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Index</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="script.js"> </script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>

<body>
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td><hr size="1" noshade></td>
  </tr>
  <tr>
    <td>
      <form action="" method="post" name="" id="">
        <table width="600" border="1" align="center" cellpadding="2" cellspacing="2">
          <tr>
            <td><input name="topcheckbox" type="checkbox" class="check" id="topcheckbox" onClick="selectall();" value="ON">
Select All &nbsp;&nbsp;&nbsp;</td>
            <td colspan="3" align="center"><a href="form.php?mode=add">Add New Record </a></td>
          </tr>
          <tr>
            <td><strong><a href="javascript:goDel()">Delete</a></strong></td>
            <td><strong>Site</strong></td>
            <td><strong>User</strong></td>
            <td><strong>Pass</strong></td>
            <td><strong>Update</strong></td>
            <td><strong>Delete</strong></td>
          </tr>
		  <?
		  include("conn.php");
		  $sql="select recordId,recordSite,recordUser,recordPass from $branch order by recordId";
		  $result=mysql_query($sql,$connection) or die(mysql_error());
		  while($row=mysql_fetch_array($result)) {
		  ?>
          <tr>
            <td><input name="<? echo $row['recordId']; ?>" type="checkbox" class="check"></td>
            <td><? echo $row['recordSite']; ?></td>
            <td><? echo $row['recordUser']; ?></td>
            <td><? echo $row['recordPass']; ?></td>
            <td><a href="<? echo "form.php?recordId=".$row['recordId']."&mode=update"; ?>">Update</a></td>
            <!--td><a href="<!--? echo "delete.php?recordId=".$row['recordId']."&mode=delete"; ?>">Delete</a></td-->
            <!--td><strong><a href="javascript:goDel()">Delete</a></strong></td-->
            <!--td><input name="<!--? echo $row['recordId']; ?>" type="checkbox" class="check"></td-->
          </tr>
		  <? } ?>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>

Open in new window


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Branch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>      <table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>
		  <?PHP
		  $mode=$_GET["mode"];
		  if($mode=="add") {
		  ?>
          <form name="form1" method="post" action="formsubmit.php?mode=add">
            <table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
              <tr>
                <td><strong>Add New Record </strong></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>Site </td>
                <td><input name="recordSite" type="text" id="recordSite"></td>
              </tr>
              <tr>
                <td>User</td>
                <td><input name="recordUser" type="text" id="recordUser"></td>
              </tr>
              <tr>
                <td>Pass</td>
                <td><input name="recordPass" type="text" id="recordPass"></td>
              </tr>
              <tr>
                <td><input type="submit" name="Submit" value="Save Data"></td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </form>
		  <?PHP		
		  } else  {
		  	include("conn.php");
			$recordId=$_GET["recordId"];
			$sql="select recordId,recordSite,recordUser, recordPass from $branch where recordId='$recordId'";
			
			$result=mysql_query($sql,$connection) or die(mysql_error());
			while($row=mysql_fetch_array($result)) {
				$recordId=$row['recordId'];
				$recordSite=$row['recordSite'];
				$recordUser=$row['recordUser'];
				$recordPass=$row['recordPass'];
			}
		?>
		<form name="form1" method="post" action="formsubmit.php?mode=update">
            <table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
              <tr>
                <td><strong>Update Record </strong></td>
                <td><input type="hidden" name="recordId" value="<? echo $recordId; ?>">
                  &nbsp;</td>
              </tr>
              <tr>
                <td>Site </td>
                <td><input name="recordSite" type="text" id="recordSite" value="<? echo $recordSite; ?>"></td>
              </tr>
              <tr>
                <td>User </td>
                <td><input name="recordUser" type="text" id="recordUser" value="<? echo $recordUser; ?>"></td>
              </tr>
              <tr>
                <td>Pass </td>
                <td><input name="recordPass" type="text" id="recordPass" value="<? echo $recordPass; ?>"></td>
              </tr>
              <tr>
                <td><input type="submit" name="Submit" value="Update Data"></td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </form>
		
		<?PHP	
			
		  }
		  ?>
		 
		  </td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

Open in new window


<?php
		  include("conn.php");
		  $mode=$_GET["mode"];
		  if($mode=="add") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="insert into $branch(recordSite,recordUser, recordPass) values('$recordSite','$recordUser','$recordPass')";
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: index.php");
			
		  } elseif($mode=="update") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="update $branch set recordSite='$recordSite',recordUser='$recordUser',recordPass='$recordPass' where recordId='$recordId'";
			//echo $sql;
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: index.php");
		  }
		  ?>

Open in new window

0
 
gr8gonzoConsultantCommented:
1. Which file is which? Is the last one the formsubmit.php?
2. Which file did you change the $_GET to $_REQUEST?
3. At the top of formsubmit.php, add:
print_r($_POST);

Then run an update, view the source of the page and past the results in here.
0
 
DS928Author Commented:
index.php is the main form after you click on "Update" form.php opens up.  When you click on "Uate Data" formsubmit.php takes over. Changed Get to Request on formsubmit.php

Array ( [recordId] => 13 [recordSite] => You Tube [recordUser] => Jerry [recordPass] => Jerry12345 [Submit] => Update Data )
Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/s/t/dstr3/html/Data/formsubmit.php:2) in /home/content/d/s/t/dstr3/html/Data/formsubmit.php on line 21
0
 
gr8gonzoConsultantCommented:
Okay, that looks promising. What's the query that's running on UPDATE (uncomment //echo $sql;) ?
0
 
gr8gonzoConsultantCommented:
Also, it's been a long day - you don't need to use $_REQUEST instead of $_GET. That was a mistake on my part. The mode=update is in the query string on the final submission URL, so it -is- in $_GET, not in $_POST.
0
 
DS928Author Commented:
This is the query...
 $sql="select recordId,recordSite,recordUser,recordPass from $branch order by recordId";

Open in new window

0
 
gr8gonzoConsultantCommented:
Sorry - I meant what is the SQL for the update query - the one commented out in this block:


} elseif($mode=="update") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="update $branch set recordSite='$recordSite',recordUser='$recordUser',recordPass='$recordPass' where recordId='$recordId'";
			//echo $sql;
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: index.php");
		  }

Open in new window

0
 
DS928Author Commented:
Not quite sure what you mean.  Isn't the $sql right above it.  In any case I put it back in....

Try the link now...

http://www.davidschure.com/index.php

getting this error
int(8) string(28) "Undefined variable: recordId" string(50) "/home/content/d/s/t/dstr3/html/Data/formsubmit.php" int(16) array(14) { ["GLOBALS"]=> *RECURSION* ["_POST"]=> array(5) { ["recordId"]=> string(2) "13" ["recordSite"]=> string(8) "You Tube" ["recordUser"]=> string(5) "Jerry" ["recordPass"]=> string(12) "Jerry1234567" ["Submit"]=> string(11) "Update Data" } ["_GET"]=> array(1) { ["mode"]=> string(6) "update" } ["_COOKIE"]=> array(0) { } ["_FILES"]=> array(0) { } ["mrno"]=> int(1) ["db_name"]=> string(8) "Chevelle" ["connection"]=> resource(3) of type (mysql link) ["db"]=> bool(true) ["branch"]=> string(7) "records" ["mode"]=> string(6) "update" ["recordSite"]=> string(8) "You Tube" ["recordUser"]=> string(5) "Jerry" ["recordPass"]=> string(12) "Jerry1234567" } update records set recordSite='You Tube',recordUser='Jerry',recordPass='Jerry1234567' where recordId=''int(2) string(132) "Cannot modify header information - headers already sent by (output started at /home/content/d/s/t/dstr3/html/Data/formsubmit.php:16)" string(50) "/home/content/d/s/t/dstr3/html/Data/formsubmit.php" int(19) array(16) { ["GLOBALS"]=> *RECURSION* ["_POST"]=> array(5) { ["recordId"]=> string(2) "13" ["recordSite"]=> string(8) "You Tube" ["recordUser"]=> string(5) "Jerry" ["recordPass"]=> string(12) "Jerry1234567" ["Submit"]=> string(11) "Update Data" } ["_GET"]=> array(1) { ["mode"]=> string(6) "update" } ["_COOKIE"]=> array(0) { } ["_FILES"]=> array(0) { } ["mrno"]=> int(1) ["db_name"]=> string(8) "Chevelle" ["connection"]=> resource(3) of type (mysql link) ["db"]=> bool(true) ["branch"]=> string(7) "records" ["mode"]=> string(6) "update" ["recordSite"]=> string(8) "You Tube" ["recordUser"]=> string(5) "Jerry" ["recordPass"]=> string(12) "Jerry1234567" ["sql"]=> string(103) "update records set recordSite='You Tube',recordUser='Jerry',recordPass='Jerry1234567' where recordId=''" ["result"]=> bool(true) }
0
 
gr8gonzoConsultantCommented:
Ah, okay.

Underneath this line in the update section:
$recordPass=$_POST["recordPass"];

...add:
$recordId = $_POST["recordId"];
0
 
gr8gonzoConsultantCommented:
When I asked you to uncomment that $sql, it was to see what the FINAL query was, with all the values inside it, in case there were any values that were not defined. In this particular case, $recordId was not defined. It was in $_POST, but it was not a local variable.
0
 
DS928Author Commented:
You did it!!   Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now