Huijari Posted August 7, 2009 Share Posted August 7, 2009 Hello again... Something is wrong with this PHP code, can't figure out what is it ... 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>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/ Share on other sites More sharing options...
Adam Posted August 7, 2009 Share Posted August 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-892734 Share on other sites More sharing options...
Huijari Posted August 7, 2009 Author Share Posted August 7, 2009 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() Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-893251 Share on other sites More sharing options...
mikesta707 Posted August 7, 2009 Share Posted August 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-893253 Share on other sites More sharing options...
Huijari Posted August 8, 2009 Author Share Posted August 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-893507 Share on other sites More sharing options...
Huijari Posted August 11, 2009 Author Share Posted August 11, 2009 Please help me! Could you maybe explain using the mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-895823 Share on other sites More sharing options...
Adam Posted August 11, 2009 Share Posted August 11, 2009 Have you read the manual? Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-895828 Share on other sites More sharing options...
Huijari Posted August 12, 2009 Author Share Posted August 12, 2009 Yes I have read it but I am not sure how to use it for this... Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-896320 Share on other sites More sharing options...
Adam Posted August 12, 2009 Share Posted August 12, 2009 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']; } Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-896351 Share on other sites More sharing options...
Adam Posted August 12, 2009 Share Posted August 12, 2009 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"); } Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-896353 Share on other sites More sharing options...
Huijari Posted August 13, 2009 Author Share Posted August 13, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-897205 Share on other sites More sharing options...
Adam Posted August 13, 2009 Share Posted August 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-897225 Share on other sites More sharing options...
Huijari Posted August 13, 2009 Author Share Posted August 13, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-897511 Share on other sites More sharing options...
Huijari Posted August 17, 2009 Author Share Posted August 17, 2009 Please could you post the fixed php code here? I have tried to use you things but I am maybe not understanding Quote Link to comment https://forums.phpfreaks.com/topic/169195-mysql-free-result-error-something-wrong-with-the-code/#findComment-900126 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.