Hi all... I've been reading this site for a while and now I have a question for you experts.

I have a php page named edit.php. Code here:

<?

// Connect database.
include("connectdb.php");


// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){



// Get parameters from form.
$id=$_POST['id'];
$date_entered=$_POST['date_entered'];
$date_completed=$_POST['date_completed'];
$location=$_POST['location'];
$person_reporting=$_POST['person_reporting'];
$solution=$_POST['solution'];

// Do update statement.
mysql_query("update greenslip set date_completed='$date_completed', location='$location',  person_reporting='$person_reporting', solution='$solution'  where id='$id'");

exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_GET['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from greenslip where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->





<html>

<head>

<script language="javascript" src="choosedate.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>New Greenslip</title>
</head>

<body>



   <!-- Begin Wrapper -->
   <div id="wrapper">
   
         <!-- Begin Header -->
         <div id="header">
		 
		       Green Slip application		 
			   
		 </div>
		 <!-- End Header -->
		 
		 <!-- Begin Navigation -->
         <div id="navigation">
		 
		       <a href="insert.htm">New Slip</a> <a href = "openslips.php">Open Slips</a> Edit Slips  <a href="closeslip.php">Close Slips</a>TESTING		 
			   
		 </div>

		 <!-- End Navigation -->		 		 
		 <!-- Begin Content -->
		 
		 <? echo $row['id']; ?>
		 

<form id="form1" name="form1" method="post" action="openslips.php">
<p>Date Entered :
<!-- name of this field is "date entered" -->
<? echo $_row['date_entered']; ?>
<br />
Date Completed :
<!-- name of this text field is "date completed" -->
<input name="date_completed" type="text" id="date_completed" value="<? echo $row['date_completed']; ?>"/>
<br />
Location :
<!-- name of this text field is "location" -->
<input name="location" type="text" id="location" value="<? echo $row['location']; ?>"/>
<br />
Person Reporting :
<!-- name of this text field is "person reporting" -->
<input name="person_reporting" type="text" id="person_reporting" value="<? echo $row['person_reporting']; ?>"/>
Solution :
<!-- name of this text field is "solution" -->
<input name="solution" type="text" id="solution" value="<? echo $row['solution']; ?>"/>

</p>

<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form> 

		<!-- end Content -->
</div>

</body>

</html>

For the life of me I can't seem to get this thing to update. I'm sure I'm missing something... Can anyone help??

Thanks,
Sean

Recommended Answers

All 13 Replies

Are you getting some kind of error, or is it simply not updating the information in the database?

Are you getting some kind of error, or is it simply not updating the information in the database?

Sorry... Yes the query is not updating the DB. Just redirecting and no update. Is my code missing something??

Thanks again...

You're actually getting the HTML code to produce a result, right? I tried copying your code into a file of my own and built a microsized database to go with it, but I can't get the HTML tags to produce any results.

Try this.

mysql_query("update greenslip set date_completed='$date_completed', location='$location',  person_reporting='$person_reporting', solution='$solution' 
 where id='$id'") or die(mysql_error());

It will show you why its not updating. Then let us know, cuz, I don't see any error in your script.

Try this.

mysql_query("update greenslip set date_completed='$date_completed', location='$location',  person_reporting='$person_reporting', solution='$solution' 
 where id='$id'") or die(mysql_error());

It will show you why its not updating. Then let us know, cuz, I don't see any error in your script.

I added the die and nothing choked. Maybe I'm making this too hard... I want to pass an id from openslips.php to edit.php so I can edit the record.
Here is openslips.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Open Greenslips</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<body>

   <!-- Begin Wrapper -->
   <div id="wrapper">
   
         <!-- Begin Header -->
         <div id="header">
		 
		       Green Slip application		 
			   
		 </div>
		 <!-- End Header -->
		 
		 <!-- Begin Navigation -->
         <div id="navigation">
		 
		       <a href="insert.htm">New Slip</a> <a href = "openslips.php">Open Slips</a> <a href="closeslip.php">Close Slips</a>		 
			   
		 </div>

		 <!-- End Navigation -->
 		 
 		 <!-- Begin Content -->
		 
		 <div id="content">

<?
// Connect database.
include("connectdb.php"); 

$result = mysql_query("SELECT * FROM greenslip where date_completed IS NULL");

echo "<table border='1'>
<tr>
<th>Date Entered</th>
<th>Date Completed</th>
<th>Location</th>
<th>Person Reporting</th>
<th>Problem</th>
<th>Solution</th>
<th>ID</th>
<th>UPDATE?</th>
<th>Delete?</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['date_entered'] . "</td>";
  echo "<td>" . $row['date_completed'] . "</td>";
  echo "<td>" . $row['location'] . "</td>";
  echo "<td>" . $row['person_reporting'] . "</td>";
  echo "<td>" . $row['problem'] . "</td>";
  echo "<td>" . $row['solution'] . "</td>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . '<a href="edit.php?id='.$row['id'].'">Update</a>' . "</td>";
  echo "<td>" . '<a href="del.php?id='.$row['id'].'">Delete</a>' . "</td>";
	
  echo "</tr>";
  }
echo "</table>";

mysql_close();
?>


</div>
		 <!-- End Content -->
		 
   </div>
   <!-- End Wrapper -->
   
</body>
</html>

Delete works like a charm (thats the easy part)... Just the edit then I can pretty up and roll it out... Any suggestions??

Thanks for the replies so far.

Sean

$id=$_POST;

You have this in your script. But where are you passing the id value ? I dont see any hidden variable where you are passing the value of id ! Put

<input type="hidden" name="id" value="<?php echo $row['id']; ?>">

this after you start the form and tell me if it works !

Cheers,
Nav

You have this in your script. But where are you passing the id value ? I dont see any hidden variable where you are passing the value of id ! Put

<input type="hidden" name="id" value="<?php echo $row['id']; ?>">

this after you start the form and tell me if it works !

Cheers,
Nav

I have the id being passed... and I can populate my form with data. Its just the update that I'm having trouble with. When I modify the data in a form field it isn't updating the db. I'm so close I can taste it.....
I think it has something to do with my update statement...

Thanks for the help...

My suggestion would be to echo the query you are using to update the table. I believe the id is not being passed to the query.

$query="update greenslip set date_completed='$date_completed', location='$location', person_reporting='$person_reporting', solution='$solution'
where id='$id'";
echo $query;

Try to echo the query first. You will know the problem with your query. But I strongly believe that its because id is not being passed.

My suggestion would be to echo the query you are using to update the table. I believe the id is not being passed to the query.

$query="update greenslip set date_completed='$date_completed', location='$location', person_reporting='$person_reporting', solution='$solution'
where id='$id'";
echo $query;

Try to echo the query first. You will know the problem with your query. But I strongly believe that its because id is not being passed.

Ok I do have the id passing to the form.
update greenslip set date_completed='', location='', person_reporting='', solution='' where id='15'

So I have the id which is auto increment on the db. when I update the record I also need to pass the id but the update statement still isn't passing the update. I'm sure I'm missing something... When I submit can I pass what is passed to the db?

Ok. Try running this update_query in phpmyadmin. If you had any problem with the query, die(mysql_error()) would have given relevant error. But since its not giving you any error, I am clueless about where exactly you have your error. Oh, btw, did you do what I asked you to do ? Did you add a hidden field with the name id ?

I have the id being passed... and I can populate my form with data.

That's because, in your other window, you are passing id in the query string and here, you are accessing it like $id=$_GET; Can you post your latest edit.php ? I am still having doubts that you can access the variable id.

Ok. Try running this update_query in phpmyadmin. If you had any problem with the query, die(mysql_error()) would have given relevant error. But since its not giving you any error, I am clueless about where exactly you have your error. Oh, btw, did you do what I asked you to do ? Did you add a hidden field with the name id ?

That's because, in your other window, you are passing id in the query string and here, you are accessing it like $id=$_GET; Can you post your latest edit.php ? I am still having doubts that you can access the variable id.

OK here is my latest edit.php

<?

// Connect database.
include("connectdb.php");


// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){



// Get parameters from form.
$id=$_POST['id'];
$date_entered=$_POST['date_entered'];
$date_completed=$_POST['date_completed'];
$location=$_POST['location'];
$person_reporting=$_POST['person_reporting'];
$solution=$_POST['solution'];

// Do update statement.
mysql_query("update greenslip set date_completed='$date_completed', location='$location',  person_reporting='$person_reporting', solution='$solution'  where id='$id'");

// Re-direct this page to select.php.
header("location:openslips.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_GET['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from greenslip where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);




// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->





<html>

<head>

<script language="javascript" src="choosedate.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>New Greenslip</title>
</head>

<body>


   <!-- Begin Wrapper -->
   <div id="wrapper">
   
         <!-- Begin Header -->
         <div id="header">
		 
		       Green Slip application		 
			   
		 </div>
		 <!-- End Header -->
		 
		 <!-- Begin Navigation -->
         <div id="navigation">
		 
		       <a href="insert.htm">New Slip</a> <a href = "openslips.php">Open Slips</a> Edit Slips  <a href="closeslip.php">Close Slips</a>TESTING		 
			   
		 </div>

		 <!-- End Navigation -->		 		 
		 <!-- Begin Content -->
		 
		 <? echo $row['id']; ?>
		 

<form id="form1" name="form1" method="post">
<p>Date Entered :
<!-- name of this field is "date entered" -->
<? echo $row['date_entered']; ?>
<br />
Date Completed :
<!-- name of this text field is "date completed" -->
<input name="date_completed" type="text" id="date_completed" value="<? echo $row['date_completed']; ?>"/>
<br />
Location :
<!-- name of this text field is "location" -->
<input name="location" type="text" id="location" value="<? echo $row['location']; ?>"/>
<br />
Person Reporting :
<!-- name of this text field is "person reporting" -->
<input name="person_reporting" type="text" id="person_reporting" value="<? echo $row['person_reporting']; ?>"/>
Solution :
<!-- name of this text field is "solution" -->
<input name="solution" type="text" id="solution" value="<? echo $row['solution']; ?>"/>

</p>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>"><p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form> 

		<!-- end Content -->
</div>

</body>

</html>

I do have the input type hidden for my id there as you said to do.

Thanks again for your help...

Looks like my date format was the culprit. Lesson learned... YYYY-MM-DD. Gotta get that through my head..

Phew! :) finally !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.