tfburges Posted November 14, 2008 Share Posted November 14, 2008 Although in the error log it says "supplied argument is not a valid MySQL-Link resource." I googled this and I'm 99% sure I haven't run out of space, nor has MySQL run out of database connections. This is the code that is causing this: copyForm("form_name_value", $selected_form_name_value, "triggers", $new_form_name_value); And the function copyForm: function copyForm($where, $sel_form_name_value, $table_with_form_name_value, $new_form_name_value_to_insert) { $query_col_names = mysql_query("SELECT * FROM `$table_with_form_name_value` ORDER BY `id` DESC LIMIT 1", $link) or die ('MYSQL error: ' . mysql_error()); $num_cols = mysql_num_fields($query_col_names); $cols = "`"; $cols_array = array(); for ($i = 1; $i < $num_cols; $i++) { if ($i == $num_cols - 1) { $cols = $cols . mysql_field_name($query_col_names, $i) . "`"; } else { $cols = $cols . mysql_field_name($query_col_names, $i) . "`,`"; } $cols_array[$i] = mysql_field_name($query_col_names, $i); } $result_last_id = mysql_fetch_array($query_col_names); $last_id = $result_last_id['id']; $last_id_plus_one = $last_id; $values = "'"; $query_for_insert = mysql_query("SELECT * FROM `$table_with_form_name_value` WHERE `$where` = '$sel_form_name_value'", $link) or die ('MYSQL error: ' . mysql_error()); while ($result_for_insert = mysql_fetch_array($query_for_insert)) { for ($i = 1; $i < $num_cols; $i++) { $col_name = $cols_array[$i]; if ($i == $num_cols - 1) { $values = $values . $result_for_insert[$col_name] . "'"; } else { $values = $values . $result_for_insert[$col_name] . "','"; } } $last_id_plus_one++; mysql_query("INSERT INTO `$table_with_form_name_value` (`id`,$cols) VALUES ('$last_id_plus_one',$values)", $link) or die ('MYSQL error: ' . mysql_error()); mysql_query("UPDATE `$table_with_form_name_value` SET `$where` = '$new_form_name_value_to_insert' WHERE `id` > '$last_id'", $link) or die ('MYSQL error: ' . mysql_error()); } } All variables are accounted for (i.e. $selected_form_name_value and $new_form_name_value). Oh... and also, the line that the error log is referring to is: $query_col_names = mysql_query("SELECT * FROM `$table_with_form_name_value` ORDER BY `id` DESC LIMIT 1", $link) or die ('MYSQL error: ' . mysql_error()); I've used the same syntax hundreds of other times and never had a problem. I'm thinking it has something to do with the fact that it's within a function... ? Quote Link to comment https://forums.phpfreaks.com/topic/132757-solved-mysql-error-but-no-error-message/ Share on other sites More sharing options...
rhodesa Posted November 14, 2008 Share Posted November 14, 2008 $link is not defined: $query_col_names = mysql_query("SELECT * FROM `$table_with_form_name_value` ORDER BY `id` DESC LIMIT 1", $link) or die ('MYSQL error: ' . mysql_error()); pass it as an argument to the function...or if there is only one mysql connection, just leave it out, as PHP will use the active connection by default Quote Link to comment https://forums.phpfreaks.com/topic/132757-solved-mysql-error-but-no-error-message/#findComment-690406 Share on other sites More sharing options...
tfburges Posted November 14, 2008 Author Share Posted November 14, 2008 Ahhhh I see! I assumed it would use the $link from earlier in the script. Thank you, sir. Quote Link to comment https://forums.phpfreaks.com/topic/132757-solved-mysql-error-but-no-error-message/#findComment-690408 Share on other sites More sharing options...
rhodesa Posted November 14, 2008 Share Posted November 14, 2008 nope...variable scope defines that variables inside a function are local to that function only Quote Link to comment https://forums.phpfreaks.com/topic/132757-solved-mysql-error-but-no-error-message/#findComment-690411 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.