Jump to content

updating single record


87dave87

Recommended Posts

Hi,

 

I want to be able to update a single record from a list of all record output from one of my database tables to mark a record as 'actioned'.  I am having trouble passing the id of a single record from the page to the database, what code would I use to do the following: -

 

UPDATE `tablename`.`details` SET `actioned` = 'yes' WHERE `details`.`id` = (ID OF RECORD FROM LOOP) LIMIT 1 ;

 

?

 

Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/142780-updating-single-record/
Share on other sites

the table should have been selected when you connected to your database:

mysql_select_db("tablename") or die(mysql_error());

 

then, use this query to update the selected data:

$query = "UPDATE details SET actioned='yes' WHERE id='$fromLoop[i]' LIMIT 1";
$result = @mysql_query($query); // this executes the sql query and saves the result in the variable "result"

 

(where "i" is the current row of the array accessed by your from loop, of course)

I now have: -

 

<?
$username="test";
$password="test";
$database="test";
mysql_connect(localhost,$username,$password);

$query = "UPDATE details SET actioned='yes' WHERE id='$id[i]' LIMIT 1";
$result = @mysql_query($query); // this executes the sql query and saves the result in the variable "result"
}

?>

The ID is shown on the page previous to the code above.  When I click the update button to action the record I get the following error: -

The website cannot display the page 
HTTP 500  
   Most likely causes:
The website is under maintenance. 
The website has a programming error. 




<?php
$username="test";
$password="test";
$database="test";
mysql_connect(localhost,$username,$password) or die(Mysql_error());

//YOU NEED TO CONNECT TO A DB

$query = "UPDATE details SET actioned='yes' WHERE id='$id[i]' LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
}

?>

 

You don't have any reference to $id, and you haven't chosen a db, see mysql_select_db()

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.