?
Solved

PHP Code Not Responding

Posted on 2011-03-14
9
Medium Priority
?
388 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:wantabe2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 1000 total points
ID: 35132455
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
 
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 1000 total points
ID: 35133139
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
 
LVL 15

Author Comment

by:wantabe2
ID: 35133530
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:Mark Brady
ID: 35134062
Yes that form will work. you have to </form> tags though so remove one of them but the form will submit properly now.
0
 
LVL 15

Author Comment

by:wantabe2
ID: 35137258
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35137690
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
 
LVL 15

Author Comment

by:wantabe2
ID: 35138013
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
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35141551
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
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35141800
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

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question