Jump to content

[SOLVED] MYSQL error... but no error message


Recommended Posts

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... ?

Link to comment
https://forums.phpfreaks.com/topic/132757-solved-mysql-error-but-no-error-message/
Share on other sites

$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

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.