powpow Posted January 14, 2011 Share Posted January 14, 2011 I have been looking at this code all day trying to find where I had results and didn't free them. Hopefully your eyes will have better luck. // if form is filled continue with script if($full == "TRUE"){ // function to concatinate two individuals string into one string function fullname($first, $last){ $fullname = "$first"." "."$last"; return $fullname; } $fullname = fullname($_POST['firstname'], $_POST['lastname']); // Check for existing user in rak5 $sql = "SELECT COUNT(*) FROM rak5 WHERE empid = '$_POST[empid]' AND fullname = '$fullname'"; $rakfcheck = mysql_query($sql); if (@mysql_result($rakfcheck,0,0) > 0) { mysql_free_result($rakfcheck); // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]'"; $UAIDcheck = mysql_query($sql); //if UAID is in the user table then check employee id for redundancy if(@mysql_result($UAIDcheck,0,0) > 0){ mysql_free_result($UAIDcheck); $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]' AND employeeID = '$_POST[empid]'"; $UAID_Empcheck = mysql_query($sql); //if there is a UAID emplid match on the user table print redundancy //else UAID is occupied by another user mysql_free_result($UAID_Empcheck); error(' Employee already has a UAID!'); } else { error('UAID is currently active by a different employee'); } } //UAID is not in the user table else{ $newpass = substr(md5($_POST['empid']),0,6); //insert new user $sql = "INSERT INTO user SET userid = '', firstname = '$_POST[firstname]', lastname = '$_POST[lastname]', email = '$_POST[newemail]', notes = '', password = ('$newpass'), UAID = '$_POST[uAID]', BOG = '', employeeID = '$_POST[empid]'"; $result = mysql_query($sql); // Email the new password to the person. $message = "G'Day! Your personal account for the Project Web Site has been created! To log in, proceed to the following address: http://ciwdvweb1.itd/web2/test2/index.php Your personal login ID and password are as follows: userid: $_POST[uAID] password: $newpass You aren't stuck with this password! Your can change it at any time after you have logged in. If you have any problems, feel free to contact me at Security Front End GUI creator "; $umail = $_POST['newemail']; mail($umail,"UAID and password", $message, "From: <[email protected]>"); include "MoveOn.html"; } } else{ error('either the name or employee id entered is incorrect please resubmit'); } } else { error('Please fill out the whole form'); } mysql_close(); endif; ?> I was wondering if it was my INSERT query but I tried to save the query into a variable and free it but I got another warning saying the variable wasn't the right parameter. Thank you for your help Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 14, 2011 Share Posted January 14, 2011 What actual problem are you trying to solve, because the php language engine will automatically free up result resources - Freeing resources Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually. Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159368 Share on other sites More sharing options...
powpow Posted January 14, 2011 Author Share Posted January 14, 2011 The problem is this warning message appears: Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0 Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159372 Share on other sites More sharing options...
BlueSkyIS Posted January 14, 2011 Share Posted January 14, 2011 i suspect the problem isn't that you've missed a mysql_free_result, but that you used one improperly. personally, i would remove them all. Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159380 Share on other sites More sharing options...
The Little Guy Posted January 14, 2011 Share Posted January 14, 2011 I bet one of your queries is invalid, and instead of giving a resource it is returning false. remove the "@" I recommend never having that. I feel it is a stupid option, and if you have to suppress errors you coded isn't well written. Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159385 Share on other sites More sharing options...
PFMaBiSmAd Posted January 14, 2011 Share Posted January 14, 2011 Ummm. That's just a warning and it is being displayed because mysql.trace_mode is on in your php.ini and you can safely turn off mysql.trace_mode. Only SELECT, SHOW, EXPLAIN, and DESCRIBE queries have result resources, so if you really want to determine which query is triggering the message, you would just need to look at those types. Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159387 Share on other sites More sharing options...
powpow Posted January 14, 2011 Author Share Posted January 14, 2011 Ummm. That's just a warning and it is being displayed because mysql.trace_mode is on in your php.ini and you can safely turn off mysql.trace_mode. Only SELECT, SHOW, EXPLAIN, and DESCRIBE queries have result resources, so if you really want to determine which query is triggering the message, you would just need to look at those types. I removed the "@" and I think I found the query that is causing the problem. $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]'"; $UAIDcheck = mysql_query($sql); Now when I was testing to see if I had debugged the Warnings I was filling out the form with the same data repeatedly. Then I realized that one part of my code shouldn't allow me to do this. The previous code sqls the database looking to see if the UAID had already been taken in the user table. The php says that there are zero users match that UAID. I have attached the out put. THe code is this: // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]'"; $UAIDcheck = mysql_query($sql); echo "<br> User input from form : $_POST[uAID] <br> mysqlresult for checking the table : "; print(mysql_result($UAIDcheck,0,0)); //if UAID is in the user table then check employee id for redundancy if(mysql_result($UAIDcheck,0,0) > 0){ [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159409 Share on other sites More sharing options...
powpow Posted January 14, 2011 Author Share Posted January 14, 2011 This is the quote i meant to select with my last post. I bet one of your queries is invalid, and instead of giving a resource it is returning false. remove the "@" I recommend never having that. I feel it is a stupid option, and if you have to suppress errors you coded isn't well written. I am going to include my whole code in case people want to try and run it over the weekend. <?php // signup.php include_once "common.php"; include_once "db.php"; if (!isset($_POST['submitok'])): // Display the user signup form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>New User Registration</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <h3>New User Registration Form</h3> <p><font color="orangered" size="+1"><tt><b>*</b></tt></font> indicates a required field</p> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> <table border="0" cellpadding="0" cellspacing="5"> <tr> <td align="right"> <p>Employee ID</p> </td> <td> <input name="empid" type="text" maxlength="100" size="25" /> <font color="orangered" size="+1"><tt><b>*</b></tt></font> </td> </tr> <tr> <td align="right"> <p>Full Name(First, Last)</p> </td> <td> <input name="firstname" type="text" maxlength="100" size="25" /> ,<input name="lastname" type="text" maxlength="100" size="25" /> <font color="orangered" size="+1"><tt><b>*</b></tt></font> </td> </tr> <tr> <td align="right"> <p>UAID</p> </td> <td> <input name="UAID" type="text" maxlength="100" size="25" /> <font color="orangered" size="+1"><tt><b>*</b></tt></font> </td> </tr> <tr> <td align="right"> <p>E-Mail Address</p> </td> <td> <input name="newemail" type="text" maxlength="100" size="25" /> <font color="orangered" size="+1"><tt><b>*</b></tt></font> </td> </tr> <tr> <td align="right" colspan="2"> <hr noshade="noshade" /> <input type="reset" value="Reset Form" /> <input type="submit" name="submitok" value=" OK " /> </td> </tr> </table> </form> </body> </html> <?php else: // function to test if all values in $_POST array are set function set($test){ $full = "TRUE"; foreach($test as $post){ if($post ==""){ $full = "FALSE"; } } return $full; } $full = set($_POST); // if form is filled continue with script if($full == "TRUE"){ // function to concatinate two individuals string into one string function fullname($first, $last){ $fullname = "$first"." "."$last"; return $fullname; } $fullname = fullname($_POST['firstname'], $_POST['lastname']); echo $fullname . "<br>"; print_r($_POST); // Check for existing user in rak5 $sql = "SELECT COUNT(*) FROM rak5 WHERE empid = '$_POST[empid]' AND fullname = '$fullname'"; $rakfcheck = @mysql_query($sql); echo "<br>"; print(mysql_result($rakfcheck,0,0)); if (mysql_result($rakfcheck,0,0) > 0) { // mysql_free_result($rakfcheck); // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]'"; $UAIDcheck = @mysql_query($sql); echo "<br> User input from form : $_POST[uAID] <br> mysqlresult for checking the table : "; print(mysql_result($UAIDcheck,0,0)); //if UAID is in the user table then check employee id for redundancy if(mysql_result($UAIDcheck,0,0) > 0){ //mysql_free_result($UAIDcheck); $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]' AND employeeID = '$_POST[empid]'"; $UAID_Empcheck = @mysql_query($sql); //if there is a UAID emplid match on the user table print redundancy //else UAID is occupied by another user if (mysql_result($UAID_Empcheck,0,0) > 0) { //mysql_free_result($UAID_Empcheck); error(' Employee already has a UAID!'); } else { error('UAID is currently active by a different employee'); } } //UAID is not in the user table else{ $newpass = substr(md5($_POST['empid']),0,6); //insert new user $sql = "INSERT INTO user SET userid = '', firstname = '$_POST[firstname]', lastname = '$_POST[lastname]', email = '$_POST[newemail]', notes = '', password = ('$newpass'), UAID = '$_POST[uAID]', BOG = '', employeeID = '$_POST[empid]'"; $result = mysql_query($sql); // Email the new password to the person. $message = "G'Day! Your personal account for the Project Web Site has been created! To log in, proceed to the following address: http://ciwdvweb1.itd/web2/test2/index.php Your personal login ID and password are as follows: userid: $_POST[uAID] password: $newpass You aren't stuck with this password! Your can change it at any time after you have logged in. If you have any problems, feel free to contact me at Security Front End GUI creator "; $umail = $_POST['newemail']; mail($umail,"UAID and password", $message, "From: <[email protected]>"); require_once "MoveOn.html"; } } else{ error('either the name or employee id entered is incorrect please resubmit'); } } else { error('Please fill out the whole form'); } endif; ?> Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159429 Share on other sites More sharing options...
BlueSkyIS Posted January 14, 2011 Share Posted January 14, 2011 there are still a lot of @'s. if there is an error in a query, it's really great to have a clue about what's wrong. @ hides the clue. $UAIDcheck = @mysql_query($sql); // BAD! $UAIDcheck = mysql_query($sql) or die(mysql_error() . " IN $sql"); // MUCH BETTER Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1159492 Share on other sites More sharing options...
powpow Posted January 17, 2011 Author Share Posted January 17, 2011 there are still a lot of @'s. if there is an error in a query, it's really great to have a clue about what's wrong. @ hides the clue. $UAIDcheck = @mysql_query($sql); // BAD! I did remove these at symbols. I noticed that my results would now result a 0. I will have to wait till tomorrow to test the die statement. I was wondering what could cause this statement to return a 0? $sql = "SELECT COUNT(*) FROM rak5 WHERE empid = $_POST[empid]' AND fullname = '$fullname'"; $rakfcheck = mysql_query($sql); echo "<br>"; print(mysql_result($rakfcheck,0,0)); if (mysql_result($rakfcheck,0,0) > 0) { // mysql_free_result($rakfcheck); // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = $_POST[uAID]'"; $UAIDcheck = mysql_query($sql); I have tested the SQL statements in myphpadmin SQL interface and when I supplement the post values with the correct input the SQL statement returns a value. Is there something wrong with my syntax? Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1160990 Share on other sites More sharing options...
BlueSkyIS Posted January 17, 2011 Share Posted January 17, 2011 if there is an error in a query, it's really great to have a clue about what's wrong. $UAIDcheck = mysql_query($sql) or die(mysql_error() . " IN $sql"); // MUCH BETTER Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1160996 Share on other sites More sharing options...
powpow Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks for your prompt reply and your help through this coding issue. I put in the die print error statements. $sql = "SELECT COUNT(*) FROM rak5 WHERE empid = '$_POST[empid]' AND fullname = '$fullname'"; $rakfcheck = mysql_query($sql) or die(mysql_error() . " IN $sql"); echo "<br>"; print(mysql_result($rakfcheck,0,0)); if (mysql_result($rakfcheck,0,0) > 0) { // mysql_free_result($rakfcheck); // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[uAID]'"; $UAIDcheck = mysql_query($sql) or die(mysql_error() . " IN $sql"); echo "<br> User input from form : $_POST[uAID] <br> mysqlresult for checking the table : "; print(mysql_result($UAIDcheck,0,0)); This is the following output. Bart Simpson Array ( [empid] => 1111 [firstname] => Bart [lastname] => Simpson [uAID] => DJV82 [newemail] => [email protected] [submitok] => OK ) 1 User input from form : DJV82 mysqlresult for checking the UAID in user table : 0 User's information emailed Warning: Unknown: 2 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0 As of right now my code will do the following. [*]It will not post unless the form is totally filled. [*]If the users' employee id and name is not recognize it will open a prompt [*]If a user was manually inserted into myphpadmin and you try to enter this information through the GUI it will respond with a prompt saying the information already exists. However, if the user is created through the GUI and you try to reenter the information it will go through the code and sql will return an error message"duplicate". I am looking to have it return my prompt error message if the user reenters the information twice. Link to comment https://forums.phpfreaks.com/topic/224433-1-result-not-freed/#findComment-1161312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.