Jump to content

Updating one column of DB ... Best way?


lightsguy

Recommended Posts

Spent most of the day trying to figure this out. I need to determine the best way to update a single column in the data base. The page that loads would show all records WHERE complete = No. Then, the user could indicate that the request has been done. (I'm not really partial to a particular method. Seeing as how I can't get any of my ideas to work, I won't argue with anything thrown out there.)

 

Once they say the request is done, the record is submitted. Currently, the page redirects back to itself (test_5.php) simply because I have no where else for it to go.

 

For the record: I know my $query as written will update every record in the DB. I never could figure out how to isolate only the records I chose. Most of what you will find below is a result of searching the archives here and other sources. Obviously, I don't know something critical, which is hampering my progress. If you can point me in the right direction, it would be greatly appreciated.

 

<?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$query = "UPDATE cable SET complete = 'Yes' WHERE complete = 'No'";
mysql_query($query) or die('Error, query failed');
unset ($_POST['add']);
include 'closedb.php';
include("test_5.php") ;
}
else
{
include 'config.php';
include 'opendb.php';
$query  = "SELECT date,emp_name, emp_email, emp_phone,server,location,switch,port FROM cable
			WHERE complete = 'No'";
$result = mysql_query($query);
echo	"<form method=\"post\"><table width=\"100%\"><tr><td>Date</td><td>Name</td><td>Email</td>" .
"<td>Phone</td><td>Group</td><td>Server</td><td>Location</td><td>Switch</td><td>Port</td>" .
"<td>Complete?</td></tr>" ;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
	echo	"<tr>	<td>{$row['date']}</td>" .
		"<td>{$row['emp_name']}</td>" .
		"<td>{$row['emp_email']}</td>" .
		"<td>{$row['emp_phone']}</td>" .
		"<td>{$row['emp_group']}</td>" .
		"<td>{$row['server']}</td>" .
		"<td>{$row['location']}</td>" .
		"<td>{$row['switch']}</td>" .
		"<td>{$row['port']}</td>" .
		"<td><select name=\"done\"><option>Yes</option><option selected>No</option></td>" ;
	} 
	echo"</tr></table><input name=\"add\" type=\"submit\" id=\"add\" value=\"Submit\"></body></html>";
	include 'closedb.php';
}

?>

Link to comment
Share on other sites

"I never could figure out how to isolate only the records I chose."

WHERE id = '$id'

 

What are you stuck on?

 

I know that I would have to set $id to match the rows that I want to update. Obviously, the only rows I want to update are the ones that are complete, and the user has indicated as so. If they chose "Yes" from the dropdown (as I have it written, which may I not work, I admit) how do I tie that to $id ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.