PHP Code Not Responding

I have some php pages that displays data from a mysql database in a browser. I need to be able to edit these records. I have an "edit" link next to each record that pulls that record up in a form so I can edit it. After I edit it, I click submit, & then for some reason I get sent to a blank page with no errors & the record does not get updated. The update)record.php code is below.
<?php  
$con = mysql_connect("localhost","uname","password");  
if (!$con)  
  {  
  die('Could not connect: ' . mysql_error());  
  }  
   
    $pacts = 'pacts'; 
    $fname = 'fname'; 
    $lname = 'lname'; 
     
mysql_select_db("psrflow", $con);  

mysql_query("UPDATE psrinfo SET pacts='".$pacts."', fname='".$fname."', lname='".$lname."'"); 


mysql_close($con); 
?>

Open in new window

LVL 15
wantabe2Asked:
Who is Participating?
 
Lukasz ChmielewskiConnect With a Mentor Commented:
I guess

$pacts = 'pacts';
    $fname = 'fname';
    $lname = 'lname';

should be

$pacts = $_POST[pacts];
    $fname = $_POST[fname];
    $lname = $_POST[lname];

It would be nice to show us the form.
0
 
Mark BradyConnect With a Mentor Principal Data EngineerCommented:
You are not getting the posted values as Roads_Roads stated.

$pacts = $_POST['pacts'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];  best to use single quotes around the posted values even if the value are of integer and not string.

We don't know how your form is sending the data (if at all) so replace $_POST[] with $_REQUEST[] and that will get the posted values. In your logic you should check to see if there are values insides the posted variables BEFORE updating the DB or you may wipe out the values in the DB with blank empty strings.

if($_REQUEST['lname'] != "" && $_REQUEST['fname'] != "" && $_REQUEST['pacts'] != ""){
// update here
mysql_query("UPDATE psrinfo SET pacts = '$pacts',fname = '$fname',lname = '$lname'")or die(mysql_error());
}else{
header("location: your_form.php");
}
0
 
wantabe2Author Commented:
The code you see above is all I have. I'll do some more reading & try to put together a form with the above code to see what I can come up with. Hopefully, I will be able to do this....let's say... the column names in the table are pacts, lname, and fname would the form code look something like this:
<html>  

 <head>  

 <title>Edit User Info</title>  

 </head>  

    

 <body>  

    

 <form action="update_record.php" method="post">  

   

 PACTS No:<br/>  

 <input type="text" value="" name="pacts" disabled/>  

 

<br/>  

    
 First Name:<br/>  
 <input type="text" value="" name="fname"/>  


 <br/>  

   

 Last Name:<br/>  

<input type="text" value="" name="lname"/>  

    

 <br/>  
   
 </br>  

   

 <input type="submit" value="submit changes"/>  


 </form>  
   

</form>  

</body>  

</html>

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Mark BradyPrincipal Data EngineerCommented:
Yes that form will work. you have to </form> tags though so remove one of them but the form will submit properly now.
0
 
wantabe2Author Commented:
Okay, I've attached my edit.php code & my update_record.php code. The edit.php code pulls the data from the mysql database & allows me to edit it. When I click the submit button, it not only updates the one unique record it pulls from the mysql database, it updates all the records. For instance, if I click "edit" on another page,  for ID 87, it pulls the information for ID 87. Then, if I just changed the fname, it changes the fname for all the records. What is going on with that?

The first code is edit.php & the second code is update_record.php
<?php # update_record.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

$result = mysql_query("SELECT * FROM psrinfo ");

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

	$errors = array(); // Initialize error array.
	
	if (empty($errors)) { // If everything's OK.
	
		// Make the query.
		$query = "UPDATE psrinfo SET pacts='$pacts', fname='$fname', lname='$lname', WHERE id=$id";
		$result = @mysql_query ($query); // Run the query.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);
}
$url .='/view_ts.php';
header("Location: $url");
exit();

		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Retrieve the user's information.
$query = "SELECT pacts, fname, lname,FROM psrinfo WHERE id = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

list($pacts, $fname, $lname, $status) = mysql_fetch_array($result, MYSQL_NUM);

?>	

<script type="text/javascript">
var valid;

function d2(v) { return (v<10)?("0"+v):v; }

function dcheck(form) {
var a = form.assgn_date.value;
var s = form.sent_date.value;
var i = form.interv_date.value;
var dr = form.due_rev.value
var su = form.due_suspo
var clk = form.due_clerk
var att = form.due_supervisor
var own = form.due_owner
var assn  = new Date(a);
var sent = new Date(s);
var intv = new Date(i);
var due_rev = new Date(dr);
var due_suspo = new Date(su);
var due_clerk = new Date(clk);
var due_supervisor = new Date(sup);
var due_owner = new Date(own);


if (isNaN(intv)) {
intv = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(assn)) {
assn = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(due_rev)) {
due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42);
}
if (isNaN(due_suspo)) {
due_suspo = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-40);
}
if (isNaN(due_clerk)) {
due_clerk = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-38);
}
if (isNaN(due_supervisor)) {
due_supervisor = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-36);
}
if (isNaN(due_owner)) {
due_owner = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-7);
}


switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_suspo.getDay()){
  case 0: due_suspo.setDate(due_suspo.getDate() - 1); // take one for Sunday
  case 6: due_suspo.setDate(due_suspo.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_clerk.getDay()){
  case 0: due_clerk.setDate(due_clerk.getDate() - 1); // take one for Sunday
  case 6: due_clerk.setDate(due_clerk.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_supervisor.getDay()){
  case 0: due_supervisor.setDate(due_supervisor.getDate() - 1); // take one for Sunday
  case 6: due_supervisor.setDate(due_supervisor.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_owner.getDay()){
  case 0: due_owner.setDate(due_owner.getDate() - 1); // take one for Sunday
  case 6: due_owner.setDate(due_owner.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

form.assgn_date.value = (assn.getFullYear()+0) + "-" + d2(assn.getMonth()+1) + "-" + d2(assn.getDate());
form.interv_date.value = (intv.getFullYear()+0) + "-" + d2(intv.getMonth()+1) + "-" + d2(intv.getDate());
form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate());
form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate());
form.due_suspo.value = (due_suspo.getFullYear()+0) + "-" + d2(due_suspo.getMonth()+1) + "-" + d2(due_suspo.getDate());
form.due_clerk.value = (due_clerk.getFullYear()+0) + "-" + d2(due_clerk.getMonth()+1) + "-" + d2(due_clerk.getDate());
form.due_supervisor.value = (due_supervisor.getFullYear()+0) + "-" + d2(due_supervisor.getMonth()+1) + "-" + d2(due_supervisor.getDate());
form.due_owner.value = (due_owner.getFullYear()+0) + "-" + d2(due_owner.getMonth()+1) + "-" + d2(due_owner.getDate());
return true;
}

</script>

<form action="update_record.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></legend>

<b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="<?php echo $pacts; ?>" /><br>
<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="<?php echo $fname; ?>" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="<?php echo $lname; ?>" /><br />


<p><input type="button" value="Calculate" onclick="return dcheck(this.form);">	<b> DO NOT enter anything below this line. Click the "Calculate" Button.</b></p>

<b>-----------------------------------------------------------</b> <br />


<br>

</fieldset>
<input type="hidden" name="submitted" value="TRUE" />

<div align="left"><input type="submit" name="submit" value="Submit" /></div>

</form>
<?php
mysql_close(); // Close the database connection.

?>

Open in new window

<?php 
$con = mysql_connect("localhost","username","password"); 
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 
  
	$pacts = $_POST['pacts']; 
    $fname = $_POST['fname']; 
    $lname = $_POST['lname'];
	
mysql_select_db("psrflow", $con); 

mysql_query("UPDATE psrinfo SET pacts='".$pacts."', fname='".$fname."', lname='".$lname."'");


mysql_close($con);
?> 


<html>  
<head>  

<title>Edit Record</title>  

</head>  

<body>  

    <b> The record has been updated!</b>

</body>  

</html>

Open in new window

0
 
Lukasz ChmielewskiCommented:
You have to add this
<input type="hidden" name="id" value="<?php echo $_REQUEST[id];?>" />
to your form and update the fields qith the query text (...) where id = $_POST[id]"
0
 
wantabe2Author Commented:
I added:
<input type="hidden" name="id" value="<?php echo $_REQUEST[id];?>" />
to the form. But I'm not sure I understand what you mean by updating the fields with the query text (...) where id = $_POST[id]"

I made the changes where I "think" they should go but it is still doing the same thing.
<?php # update_record.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

$result = mysql_query("SELECT * FROM psrinfo ");

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

	$errors = array(); // Initialize error array.
	
	if (empty($errors)) { // If everything's OK.
	
		// Make the query.
		$query = "UPDATE psrinfo SET pacts='$pacts', fname='$fname', lname='$lname', WHERE id=$id";
		$result = @mysql_query ($query); // Run the query.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);
}
$url .='/view_ts.php';
header("Location: $url");
exit();

		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Retrieve the user's information.
$query = "SELECT pacts, fname, lname,FROM psrinfo WHERE id = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

list($pacts, $fname, $lname, $status) = mysql_fetch_array($result, MYSQL_NUM);

?>	

<script type="text/javascript">
var valid;

function d2(v) { return (v<10)?("0"+v):v; }

function dcheck(form) {
var a = form.assgn_date.value;
var s = form.sent_date.value;
var i = form.interv_date.value;
var dr = form.due_rev.value
var su = form.due_suspo
var clk = form.due_clerk
var att = form.due_supervisor
var own = form.due_owner
var assn  = new Date(a);
var sent = new Date(s);
var intv = new Date(i);
var due_rev = new Date(dr);
var due_suspo = new Date(su);
var due_clerk = new Date(clk);
var due_supervisor = new Date(sup);
var due_owner = new Date(own);


if (isNaN(intv)) {
intv = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(assn)) {
assn = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(due_rev)) {
due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42);
}
if (isNaN(due_suspo)) {
due_suspo = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-40);
}
if (isNaN(due_clerk)) {
due_clerk = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-38);
}
if (isNaN(due_supervisor)) {
due_supervisor = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-36);
}
if (isNaN(due_owner)) {
due_owner = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-7);
}


switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_suspo.getDay()){
  case 0: due_suspo.setDate(due_suspo.getDate() - 1); // take one for Sunday
  case 6: due_suspo.setDate(due_suspo.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_clerk.getDay()){
  case 0: due_clerk.setDate(due_clerk.getDate() - 1); // take one for Sunday
  case 6: due_clerk.setDate(due_clerk.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_supervisor.getDay()){
  case 0: due_supervisor.setDate(due_supervisor.getDate() - 1); // take one for Sunday
  case 6: due_supervisor.setDate(due_supervisor.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_owner.getDay()){
  case 0: due_owner.setDate(due_owner.getDate() - 1); // take one for Sunday
  case 6: due_owner.setDate(due_owner.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

form.assgn_date.value = (assn.getFullYear()+0) + "-" + d2(assn.getMonth()+1) + "-" + d2(assn.getDate());
form.interv_date.value = (intv.getFullYear()+0) + "-" + d2(intv.getMonth()+1) + "-" + d2(intv.getDate());
form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate());
form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate());
form.due_suspo.value = (due_suspo.getFullYear()+0) + "-" + d2(due_suspo.getMonth()+1) + "-" + d2(due_suspo.getDate());
form.due_clerk.value = (due_clerk.getFullYear()+0) + "-" + d2(due_clerk.getMonth()+1) + "-" + d2(due_clerk.getDate());
form.due_supervisor.value = (due_supervisor.getFullYear()+0) + "-" + d2(due_supervisor.getMonth()+1) + "-" + d2(due_supervisor.getDate());
form.due_owner.value = (due_owner.getFullYear()+0) + "-" + d2(due_owner.getMonth()+1) + "-" + d2(due_owner.getDate());
return true;
}

</script>

<form action="update_record.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></legend>

<b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="<?php echo $pacts; ?>" /><br>
<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="<?php echo $fname; ?>" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="<?php echo $lname; ?>" /><br />


<p><input type="button" value="Calculate" onclick="return dcheck(this.form);">	<b> DO NOT enter anything below this line. Click the "Calculate" Button.</b></p>

<b>-----------------------------------------------------------</b> <br />


<br>

</fieldset>
<input type="hidden" name="id" value="<?php echo $_REQUEST[id];?>" />

<div align="left"><input type="submit" name="submit" value="Submit" /></div>

</form>
<?php
mysql_close(); // Close the database connection.

?>

Open in new window

<?php # update_record.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

$result = mysql_query("SELECT * FROM psrinfo ");

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

	$errors = array(); // Initialize error array.
	
	if (empty($errors)) { // If everything's OK.
	
		// Make the query.
		$query = "UPDATE psrinfo SET pacts='$pacts', fname='$fname', lname='$lname', WHERE id=$_POST[id]";
		$result = @mysql_query ($query); // Run the query.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);
}
$url .='/view_ts.php';
header("Location: $url");
exit();

		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Retrieve the user's information.
$query = "SELECT pacts, fname, lname,FROM psrinfo WHERE id = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

list($pacts, $fname, $lname, $status) = mysql_fetch_array($result, MYSQL_NUM);

?>	

<script type="text/javascript">
var valid;

function d2(v) { return (v<10)?("0"+v):v; }

function dcheck(form) {
var a = form.assgn_date.value;
var s = form.sent_date.value;
var i = form.interv_date.value;
var dr = form.due_rev.value
var su = form.due_suspo
var clk = form.due_clerk
var att = form.due_supervisor
var own = form.due_owner
var assn  = new Date(a);
var sent = new Date(s);
var intv = new Date(i);
var due_rev = new Date(dr);
var due_suspo = new Date(su);
var due_clerk = new Date(clk);
var due_supervisor = new Date(sup);
var due_owner = new Date(own);


if (isNaN(intv)) {
intv = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(assn)) {
assn = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(due_rev)) {
due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42);
}
if (isNaN(due_suspo)) {
due_suspo = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-40);
}
if (isNaN(due_clerk)) {
due_clerk = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-38);
}
if (isNaN(due_supervisor)) {
due_supervisor = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-36);
}
if (isNaN(due_owner)) {
due_owner = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-7);
}


switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_suspo.getDay()){
  case 0: due_suspo.setDate(due_suspo.getDate() - 1); // take one for Sunday
  case 6: due_suspo.setDate(due_suspo.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_clerk.getDay()){
  case 0: due_clerk.setDate(due_clerk.getDate() - 1); // take one for Sunday
  case 6: due_clerk.setDate(due_clerk.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_supervisor.getDay()){
  case 0: due_supervisor.setDate(due_supervisor.getDate() - 1); // take one for Sunday
  case 6: due_supervisor.setDate(due_supervisor.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_owner.getDay()){
  case 0: due_owner.setDate(due_owner.getDate() - 1); // take one for Sunday
  case 6: due_owner.setDate(due_owner.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

form.assgn_date.value = (assn.getFullYear()+0) + "-" + d2(assn.getMonth()+1) + "-" + d2(assn.getDate());
form.interv_date.value = (intv.getFullYear()+0) + "-" + d2(intv.getMonth()+1) + "-" + d2(intv.getDate());
form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate());
form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate());
form.due_suspo.value = (due_suspo.getFullYear()+0) + "-" + d2(due_suspo.getMonth()+1) + "-" + d2(due_suspo.getDate());
form.due_clerk.value = (due_clerk.getFullYear()+0) + "-" + d2(due_clerk.getMonth()+1) + "-" + d2(due_clerk.getDate());
form.due_supervisor.value = (due_supervisor.getFullYear()+0) + "-" + d2(due_supervisor.getMonth()+1) + "-" + d2(due_supervisor.getDate());
form.due_owner.value = (due_owner.getFullYear()+0) + "-" + d2(due_owner.getMonth()+1) + "-" + d2(due_owner.getDate());
return true;
}

</script>

<form action="update_record.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></legend>

<b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="<?php echo $pacts; ?>" /><br>
<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="<?php echo $fname; ?>" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="<?php echo $lname; ?>" /><br />


<p><input type="button" value="Calculate" onclick="return dcheck(this.form);">	<b> DO NOT enter anything below this line. Click the "Calculate" Button.</b></p>

<b>-----------------------------------------------------------</b> <br />


<br>

</fieldset>
<input type="hidden" name="submitted" value="TRUE" />

<div align="left"><input type="submit" name="submit" value="Submit" /></div>

</form>
<?php
mysql_close(); // Close the database connection.

?>

Open in new window

0
 
Mark BradyPrincipal Data EngineerCommented:
Wantabe2: you have got you code all round the wrong way. In the first code you posted (the form), you are trying to update the database right there on that page before anything has been posted. You need to remove lines 15 down to 25 from your form. In fact, I will redo your form and redo the update query for you. You can add all that non-sensical rubbish code into the form if you wish but it is all not neccessary. Give me a few minutes to retype it all.
0
 
Mark BradyPrincipal Data EngineerCommented:
Actually I haven't got time to rewrite the whole code. Let me tell you where I think your logic is wrong.

firstly, in your first code (the form page) I am assuming you are posting another form to this page to tell it which $id to load the details for correct? If so, where are you getting the posted ID number from? you are not asking for it anywhere that I can see so you need to add a line

$id = $_POST['id'];
or
$id = $_REQUEST['id'];

You should use the first line as you know the form is using the $_POST[] method. Only use REQUEST if you don't know how the data is being sent.

Moving on. Lines 24 and 25 is updating the database where id = $id but you haven't set $id yet. See my first paragraph. You don't want to update the database in this page you are doing it in your update_record.php page so remove those two lines.

 In your form, you have got two buttons, one that says 'Calculate' and the other 'Submit'. you are expecting people to fill out a form then click two buttons to submit the form? Wow, not many would want to do that. You want to check that the data is good but don't ask the user to click a button to verify they have filled it in. Do it automatically.

That last part is a suggestion not a mistake on your part. Try fixing up those few problems and see how it runs. You need to make sure the form is sending an id (you need to check it). In your other form it is a good idea to check for a value in the $_POST['id']; Try echoing it to make sure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.