MrCreeky Posted November 27, 2012 Share Posted November 27, 2012 Hi, I'm trying to come up with a solution to move multiple entries to a different table in one end user click. For example, I have a table called "Service". Within that table I have a number of fields "id,row-1,row-2,row-3,row-4" Within the service row-1 will have the same value for a number of entries that are displayed to the end user on one page showing a catalogue of information. The id will of course be unique. I need to be abel to move all the rows from the service table that have the same value based in row-1. At the moment I'm trying to filter this information based on a URL Permitter (?id=) I'm passing to the page however I have run in to some problems I don't understand. Here is how I have been trying to filter the data and copy it over the "Archive" table. $colname_move_rs = "-1"; if (isset($_GET['id'])) { $colname_move_rs = $_GET['id']; } mysql_select_db($database_encomSQL, $encomSQL); $query_move_rs = sprintf("INSERT INTO archive (row-1,row-2,row-3,row-4) SELECT row-1,row-2,row-3,row-4 FROM service WHERE row-1 = %s", GetSQLValueString($colname_move_rs, "int")); $move_rs = mysql_query($query_move_rs, $encomSQL) or die(mysql_error()); $row_move_rs = mysql_fetch_assoc($move_rs); $totalRows_move_rs = mysql_num_rows($move_rs); The type of errors I'm getting are as follows: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in move.php on line 41 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in move.php on line 42 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in move.php on line 44 If anyone could offer me some help, I would be most grateful! Quote Link to comment https://forums.phpfreaks.com/topic/271258-moving-table-rows-to-different-tables/ Share on other sites More sharing options...
mrMarcus Posted November 27, 2012 Share Posted November 27, 2012 (edited) Hyphenated column names are no good. Use backticks ` to clear the issue. $query_move_rs = sprintf("INSERT INTO archive (`row-1`,`row-2`,`row-3`,`row-4`) SELECT `row-1`,`row-2`,`row-3`,`row-4` FROM service WHERE `row-1` = %s", GetSQLValueString($colname_move_rs, "int")); EDIT: I noticed that your code is dependent on $_GET['id'] existing. However, this block of code isn't helping the cause: $colname_move_rs = "-1"; if (isset($_GET['id'])) { $colname_move_rs = $_GET['id']; } If $_GET['id'] isn't set, $colname_move_rs is equal to -1. Now, I'm not sure that that is OK in your books, but I wouldn't think so. Your query should not fire unless an appropriate value for $_GET['id'] is found. Not only checking if it isset, but checking whether a value even exists and whether that value is numeric or not. If $_GET['id'] == 'string', that is no good for your query. So, check value exists and check what that value is (numeric or string). Then, if it checks out, execute your query. Edited November 27, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271258-moving-table-rows-to-different-tables/#findComment-1395626 Share on other sites More sharing options...
mikosiko Posted November 28, 2012 Share Posted November 28, 2012 Read http://php.net/manual/en/function.mysql-query.php Pay special attention to the "Returned Values" section, it will explain the errors that you are getting Quote Link to comment https://forums.phpfreaks.com/topic/271258-moving-table-rows-to-different-tables/#findComment-1395887 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.