Jump to content

MySql Free Result Error: Something wrong with the code...


Recommended Posts

Hello again... Something is wrong with this PHP code, can't figure out what is it  :facewall:

... Getting mysql_free_result error ... and maybe something else

 

<?php

print("<html>");
print("<head>");
print("<title>Auction Bulk Relisting Tool</title>");
print("</head>");
print("<body bgcolor=\"#FFFFFF\" link=\"#800080\" vlink=\"#400040\" alink=\"#8E85CF\">");
print("<div align=\"center\">");
print("<table width=580>");
print("<tr>");
print("<td align=\"CENTER\" width=200>");
print("<img src=\"LOGO.GIF\"></td></tr></table><BR>");

// change or remove previous line for LOGO
  

//connect to the database

$conn = mysql_connect("localhost","myusername","mypass");
mysql_select_db("mydatabase" , $conn);


$desc=array();
$prix=array();
$duree=array();
$B_Now=array();
$title=array();
$lot=array();


// check if update mode

if (isset($_GET['action']) && $_GET['action'] == "update") 

  
  
{
     
    // each auction # to relist



if (count($relist) > 0)
{
 $nlot =  count($relist); 

 for ($i = 0;
 $i < $nlot ;
  $i++)
  {
// relist selected auctions

$lot[$i] = $relist[$i];
$resulti = mysql_query("select * from webid_auctions where id = $lot[$i]", $conn);
   
   
  $duration = mysql_result($resulti, 0, "duration");

$closed =  mysql_result ($resulti, 0, "closed");
	$n_relist = mysql_result ($resulti, 0, "relisted") + 1;

 $a_start = time();  // start right now
 $a_end = $a_start + (($duration * 24 * 60 * 60) + ($i * 300));  // add 5 minutes to end time between auctions thus the $i*300



mysql_free_result($resulti);

    $result2 = mysql_query("update webid_auctions set starts = '$a_start' where id = $lot[$i]", $conn);
    $result1 = mysql_query("update webid_auctions set ends = '$a_end' where id = $lot[$i]" , $conn);

    $result3 = mysql_query("update webid_auctions set closed = '0'  where id = $lot[$i]", $conn);
    $result4 = mysql_query("update webid_auctions set relisted = '$n_relist' where id = $lot[$i]" , $conn);

 print (" AUCTION \"$relist[$i]\" has been relisted successfully<BR>");
 	}
	}

else
{
echo " NEED TO MAKE AT LEAST ONE SELECTION - use BACK button and select";
}
mysql_free_result($result1);
mysql_free_result($result2);
mysql_free_result($result3);
mysql_free_result($result4);
exit;
}

// LIST OPTION

if (!isset($_GET['action']) && $_GET['action'] != "update")
{

// LOOK UP CLOSED AUCTIONS NOT RELISTED AND UNSOLD

$result = mysql_query("select * from webid_auctions where closed = '1' and num_bids = '0' ", $conn);

// HOW MANY FOUND

$numlot = mysql_num_rows($result);

for ($i = 0;
$i < $numlot;
$i++)

{ 
// SAVE THEM IN ARRAY

$lot[$i] = mysql_result ($result, $i, "id");
$title[$i] = mysql_result ($result, $i, "title");
$duree[$i] = mysql_result ($result, $i, "duration");
$B_Now[$i] = mysql_result ($result, $i, "buy_now");
$prix[$i] = mysql_result ($result, $i, "minimum_bid");

}


print("<h1>CLOSED AUCTIONS <BR></H1><table BORDER=\"1\" CELLPADDING=\"2\" ALIGN=\"Center\">\n");
print("<tr>\n");
print("<td><p ALIGN=\"Center\"><font COLOR=\"#ff0080\">select</font></td>\n");
print("<td><p ALIGN=\"Center\"><font COLOR=\"#ff0080\">Title</font></td>\n");
print("<td><p ALIGN=\"Center\"><font COLOR=\"#8000ff\">Price</font></td>\n");
print("<td><p ALIGN=\"Center\"><font COLOR=\"#ff0080\">Buy Now</font></td>\n");
print("<td><p ALIGN=\"Center\"><font COLOR=\"#ff0080\">Days</font></td>\n");
print("<FORM action=\"http://www.mysite.net/bulk_relist_auctions.php\">"); // change to your URL
print("<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"update\">");

for ($i = 0;
$i < $numlot;
$i++){ 

print("<tr>\n");
print("<td><input type=\"checkbox\" name=\"relist[]\" value=\"$lot[$i]\">
</td>\n");
print("<td>$title[$i]</td>\n");
print("<td>$prix[$i]</td>\n");
print("<td>$B_Now[$i]</td>\n");
print("<td>$duree[$i]</td>\n");
print("<td>");

}



print("</TR></TABLE><INPUT TYPE=\"SUBMIT\" VALUE=\"Submit Form\">");
print("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">");
print("</FORM>");
}
?>

What line is it saying this is at? What might the other thing be?

 

You're perhaps over-using the memory and it's trying to tell you to use mysql_free_result. Just a quick skim through all that code I can already see 4 update queries that could all be done in 1. Several calls to mysql_result that could be handled with one function - mysql_fetch_assoc. Badly written code.

It is saying this:

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/bulk_relist_auctions.php on line 83
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/bulk_relist_auctions.php on line 84
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/bulk_relist_auctions.php on line 85
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/bulk_relist_auctions.php on line 86

Those lines are:

 

	mysql_free_result($result1);
mysql_free_result($result2);
mysql_free_result($result3);
mysql_free_result($result4);

 

And could you help me with that mysql_fetchassoc()

well firstly, try doing

or die("ERROR: " . mysql_error());

 

whenever you do a mysql query. There is probably a problem with the query, resulting in a return value of false, rather than returning a valid mySQL resource.

Ok I did. Now it says: Parse error: syntax error, unexpected T_LOGICAL_OR in /home/a5292922/public_html/bulk_relist_auctions.php on line 55

 

That line:

$resulti = mysql_query("select * from webid_auctions where id = $lot[$i]", $conn);

 

 

What could be wrong?  :confused:

Okay, so consider this:

 

$lot[$i] = mysql_result ($result, $i, "id");
$title[$i] = mysql_result ($result, $i, "title");
$duree[$i] = mysql_result ($result, $i, "duration");
$B_Now[$i] = mysql_result ($result, $i, "buy_now");
$prix[$i] = mysql_result ($result, $i, "minimum_bid");

 

It would be changed to this:

 

while ($row = mysql_fetch_assoc($result))
{
    $lot[]   = $row['id'];
    $title[] = $row['title'];
    $duree[] = $row['duration'];
    $B_Now[] = $row['buy_now'];
    $prix[]  = $row['minimum_bid'];
}

Sorry from your code I missed part of it out, the block that would replace is:

 

$numlot = mysql_num_rows($result);

for ($i = 0;
$i < $numlot;
$i++)

{ 
// SAVE THEM IN ARRAY

$lot[$i] = mysql_result ($result, $i, "id");
$title[$i] = mysql_result ($result, $i, "title");
$duree[$i] = mysql_result ($result, $i, "duration");
$B_Now[$i] = mysql_result ($result, $i, "buy_now");
$prix[$i] = mysql_result ($result, $i, "minimum_bid");

}

Ok I tried this:

 

$numlot = mysql_num_rows($result);

for ($i = 0;
$i < $numlot;
$i++)

{ 
// SAVE THEM IN ARRAY

$lot[$i] = mysql_result ($result, $i, "id");
$title[$i] = mysql_result ($result, $i, "title");
$duree[$i] = mysql_result ($result, $i, "duration");
$B_Now[$i] = mysql_result ($result, $i, "buy_now");
$prix[$i] = mysql_result ($result, $i, "minimum_bid");

}

 

CHANGED TO THIS:

 

while ($row = mysql_fetch_assoc($result))
{
    $lot[]   = $row['id'];
    $title[] = $row['title'];
    $duree[] = $row['duration'];
    $B_Now[] = $row['buy_now'];
    $prix[]  = $row['minimum_bid'];
}

 

It is still saying the same:

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/myykaikki.php on line 83

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/myykaikki.php on line 84

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/myykaikki.php on line 85

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/a5292922/public_html/myykaikki.php on line 86

You're placing them out of the IF block in which the 'result resources' are created. This means that unless 'count($relist) > 0' (line 43) they're trying to free the result memory of a resource that doesn't exist. Move them within the if block. As it says in the manual for mysql_free_result, you only really need to use this if you're 'concerned about how much memory is being used'. In the updates:

 

    $result2 = mysql_query("update webid_auctions set starts = '$a_start' where id = $lot[$i]", $conn);
    $result1 = mysql_query("update webid_auctions set ends = '$a_end' where id = $lot[$i]" , $conn);

    $result3 = mysql_query("update webid_auctions set closed = '0'  where id = $lot[$i]", $conn);
    $result4 = mysql_query("update webid_auctions set relisted = '$n_relist' where id = $lot[$i]" , $conn);

 

Roughly how many records are updated?

I am not sure do I understand...

 

But firstly when I replace this:

 

$numlot = mysql_num_rows($result);

for ($i = 0;
$i < $numlot;
$i++)

{ 
// SAVE THEM IN ARRAY

$lot[$i] = mysql_result ($result, $i, "id");
$title[$i] = mysql_result ($result, $i, "title");
$duree[$i] = mysql_result ($result, $i, "duration");
$B_Now[$i] = mysql_result ($result, $i, "buy_now");
$prix[$i] = mysql_result ($result, $i, "minimum_bid");

}

 

TO THIS:

 

while ($row = mysql_fetch_assoc($result))
{
    $lot[]   = $row['id'];
    $title[] = $row['title'];
    $duree[] = $row['duration'];
    $B_Now[] = $row['buy_now'];
    $prix[]  = $row['minimum_bid'];
}

 

Then there is nothing in the list ( There should be seen some items, (auctions))

 

And do you mean I have to move this:

 

    $result2 = mysql_query("update webid_auctions set starts = '$a_start' where id = $lot[$i]", $conn);
    $result1 = mysql_query("update webid_auctions set ends = '$a_end' where id = $lot[$i]" , $conn);

    $result3 = mysql_query("update webid_auctions set closed = '0'  where id = $lot[$i]", $conn);
    $result4 = mysql_query("update webid_auctions set relisted = '$n_relist' where id = $lot[$i]" , $conn);

 

To under the

if (count($relist) > 0)

 

Please help I am not the best with php.

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.