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
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)

Link to comment
Share on other sites

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. 




Link to comment
Share on other sites

<?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()

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.