October 9, 201214 yr Hi all. I've got a while loop displaying a list of tasks. The form to create the tasks has 3 fields, so this would be the typical input: id: 1 task: buy milk status: active The while loop containing all the added tasks is displayed on another page. Here's the code: <?php require_once('Connections/testdb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_testdb, $testdb); $query_Recordset1 = "SELECT * FROM tasks WHERE status = 'active'"; $Recordset1 = mysql_query($query_Recordset1, $testdb) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <html> <head> </head> <script type="text/javascript"> $(document).ready(function(){ $("#done").click(function(){ $.post( 'archiveTask.php', { id:$("#id").val(), status:$("#status").val() }) return false; }); }); </script> <body> <form id="commentForm2" > <?php do { ?> <table width="176" border="1"> <tr> <td><input name="id" type="text" id="id" value="<?php echo $row_Recordset1['id']; ?>"></td> <td><input name="task" type="text" id="task" value="<?php echo $row_Recordset1['task']; ?>"></td> <td><input name="status" type="hidden" id="status" value="inactive"></td> <td><input type="submit" name="done" class="done" id="done" value="Done" /></td> </tr> </table> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </form> </body> </html> <?php mysql_free_result($Recordset1); ?> I'm trying to modify this code so that when the 'done' button is clicked, the record on that table row posts to a processing page (archiveTask.php) and the record's 'status' is updated to 'inactive' (using the hidden field above with value of 'inactive'). Then the record shouldn't show in the loop any longer as the recordset is only displaying records where status = 'active'. Here is the code from archiveTask.php, which should update 'status' to 'inactive' <?php $host = "localhost"; $dbname = "testdb"; $user = "root"; $pass = "xxxxxx"; $conn = mysql_connect($host, $user, $pass) or die(MYSQL_ERROR); $select_db = mysql_select_db($dbname) or die("Could not connect"); $id = $_POST['id']; $task = $_POST['task']; $status = $_POST['status']; $sql = "UPDATE tasks SET status = $status where id = $id"; mysql_query($sql) or die("Could not execute query"); ?> I'm a bit new to this - can anyone see where I'm going wrong? Thanks guys, appreciate any help
Create an account or sign in to comment