87dave87 Posted January 28, 2009 Share Posted January 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
87dave87 Posted January 29, 2009 Author Share Posted January 29, 2009 can anyone help me with this? Quote Link to comment Share on other sites More sharing options...
Errant_Shadow Posted January 29, 2009 Share Posted January 29, 2009 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) Quote Link to comment Share on other sites More sharing options...
87dave87 Posted January 29, 2009 Author Share Posted January 29, 2009 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. Quote Link to comment Share on other sites More sharing options...
gevans Posted January 29, 2009 Share Posted January 29, 2009 <?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() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.