Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. If you search for that error message, you will find that it generally means that your query failed due to an error of some kind. For debugging purposes, use mysql_error() in an or die() statement to get your code to tell you why - $numresultsProd=mysql_query($queryProd) or die(mysql_error()); $numresultsCat=mysql_query($queryCat) or die(mysql_error()); I'll bet it is something to do with your database connection or a nonexistent database table.
  2. The mysql_query() statement is outside/after the end of the if($_POST['action'] == 'Register'){} conditional statement where the $query variable is defined, so, every time the page is requested, regardless of the $_POST['action'] value, $query is referenced, resulting in a php error being generated. The mysql_query() statement should be inside the if($_POST['action'] == 'Register'){...} conditional statement where the $query variable is defined so that it is only executed when the form was submitted and the $query variable has a value. Also, your if/elseif logic testing the $_POST['newsletter'] value allows the query to be executed when the $_POST['newsletter'] value does not match any of the possible choices. You should make sure that value is one of the choices. If it is not, you should output a user messages alerting them that an invalid value was selected and don't execute the query. Finally, if after making those changes to the logic, you think you are submitting one of the choices but your code did not match it, you would need to troubleshoot what the actual submitted value is. Using echo or var_dump on the $_POST['newsletter'] variable would display what it contains.
  3. You would need to retrieve the current data (or pass it through the form somehow), then compare the original values with the submitted values. Either method would all take extra time and more code. However, there's little point in doing that because if you try to UPDATE a value to the same value it already is, mysql doesn't actually go to the trouble of writing the value to the database. So, if none of the values in a row are changed, yes you would still be executing an UPDATE query, but mysql would short-circuit the process and not actually take the time to write the row back into the database.
  4. Your form does not have a method="post" attribute, so the data is being sent via GET.
  5. Basically, you could do this - <?php $checkboxFields = array( 'fact-sent', 'fact-payed', 'domain', 'content','design-sent', 'design-approved', 'design-sliced', 'temp-website', 'temp-website-sent', 'temp-website-approved', 'cms', 'seo', 'analytics', 'webmaster-tools', 'website', 'website-online'); echo "<pre>",print_r($_POST,true),"</pre>"; if(isset($_POST['submit'])) { $pivot = array(); // swap the columns and rows foreach($checkboxFields as $fieldName){ if(isset($_POST[$fieldName])){ // at least one checkbox is set foreach($_POST[$fieldName] as $project=>$dummy){ $pivot[$project][] = $fieldName; } } } echo "<pre>",print_r($pivot,true),"</pre>"; foreach($pivot as $project=>$array){ $fields = array(); foreach($checkboxFields as $fieldName){ if(in_array($fieldName,$array)){ $fields[] = "`$fieldName` = TRUE"; // whatever value you are using to indicate checked } else { $fields[] = "`$fieldName` = NULL"; // whatever value you are using to indicate not-checked } } $query = "UPDATE your_table SET " . implode(',',$fields) . " WHERE project = $project"; echo $query . "<br />"; // execute your query here } }
  6. In your other thread for this problem, mjdamato both told and showed how to use one big form and identify which record the checkbox belong with - The fieldname portion of that would be your $fieldName variable. The recordID would apparently be from $row['project']
  7. If you changed the method from what you are doing in the code you posted (one form for each row of data, not one big form holding all the data), you would need to post your current code.
  8. As already stated, php automatically closes connections (when the script on any page ends.) Barring a bug in your php version that prevents that or you are using persistent connections somewhere (and your web server/php combination even supports persistent connections), connections will not normally be left open if there are no instances of your page being requested. And as already asked, what is the exact wording of the error messages or what exactly is the information that your web host provided? It should be explicate about who,what,when, where, and how many connections, otherwise it is just a rumor and it is extremely hard to fix rumors in programming.
  9. Since php automatically closes connections (provided you are not using persistent connections or you have a version of php with a bug in the exit/cleanup code), the only way that code could result in "too many connections" would be if the page is making more than one connection or you simply have a popular site that has enough concurrent visitors (or a hacker intentionally trying to trigger errors) to that page that you are exceeding the maximum number of connections that your web host permits. Do any of the other files that are being included make a database connection, or perhaps have a dynamically produced image that is making a database connection? What exactly is the mysql_connect() code? What's the exact wording of the error messages?
  10. I moved your thread to the 3rd party scripts because the actual attached source code contains comments (that you intentionally omitted in the posted code) indicating it is a copyrighted/paid license script, because of your difficulty with troubleshooting php problems in the script, and reluctance to provide asked for information. It was very likely you were someone attempting to get a poorly written 3rd party script working, rather than the author of the script. Having studied the source code more (based on the error messages posted in Reply #22), I can tell you why you are getting errors concerning the BASEPATH defined constant. The code you posted at the start of the thread, using index.php and core.php is not actually where the problem is. The problem is that you are redirecting to the error.php page and it is only requiring 'common.php'. The code in common.php is dependent on a constant that is defined in index.php. For some of the other errors, I suspect you have been randomly changing the code, but have not provided the actual code that is running that is producing the errors you want help with. If you are going to be redirecting to an 'error' page, that page must be a complete web page that requires everything that it needs. error.php should require core.php, the same as what index.php is doing. As to your last error concerning the $_DB variable. You would need to post the exact and complete code that reproduces that error for anyone in a help forum to have a chance at determining what is causing the problem.
  11. To reference that team header information before the start of the loop, you could use mysql_result Alternatively, you could fetch the first row (your existing logic), then use mysql_data_seek to return the pointer to the 0'th row.
  12. DATE_FORMAT(datePublished, '%D %M %Y @ %H:%i' ) AS use_a_different_name_here, ORDER BY datePublished <---- so that the ORDER BY will use your datePublished column values instead of the DATE_FORMAT() output.
  13. $team = mysql_fetch_assoc($results); <---- you are fetching the first row of data from the result set before the start of your while(){} loop, so of course the first player information is missing.
  14. Use a DIFFERENT alias name for the DATE_FORMAT output so that mysql can order by your original column, not the DATE_FORMAT output.
  15. ^^^ That only tests if the query executed with an error of some kind, i.e. a connection problem, a sql syntax error, a mistyped table or column name, ... A query that matches zero rows is a successful query and returns a result resource, that contains zero rows. See mysql_num_rows to determine how many rows a successful query returned.
  16. If you are making a separate form for each row of data (your current code), by definition, that means that you can only submit one at a time. The id you put into the hidden field would uniquely identify which row you would update in the database table.
  17. http://us2.php.net/manual/en/features.file-upload.errors.php You must test if the upload worked (['error'] is a zero) before you can access any of the uploaded file information.
  18. When you used var_dump($_FILES), did you happen to notice what the ['error'] element was?
  19. Here's the posted code 'fixed' to correct the order of the code on the page and to clean up and eliminate a lot of unnecessary code and passing values through the link - <?php session_start(); if(!isset($_SESSION['user'])){ header("Location: index.php"); // not logged in, go elsewhere exit; // prevent the remainder of the code on this page from executing } include('connect.php'); // perform any actions/processing for the page request if(isset($_GET['use'])){ $use_id = (int)$_GET['id']; // cast value as an integer to prevent sql injection/cheating // get the data for the item requested $query = "SELECT * FROM player_items WHERE id = $use_id AND Username = '{$_SESSION['user']}'"; if(!$result = mysql_query($query)){ // query failed, handle the error here... die(mysql_error()); } else { // query worked without any errors if(!mysql_num_rows($result)){ // no matching row, user no longer has this item // do whatever processing you want for this condition here... } else { // user has the item $row = mysql_fetch_assoc($result); // get the data $use_type = $row['Type']; $use_value = $row['Value']; if($use_type == "Credits"){ $use_type = "Current_Credits"; } // you should really fix this by renaming the column to match the expected value mysql_query("UPDATE stats SET `$use_type` = `$use_type` + $use_value WHERE Username = '{$_SESSION['user']}'") or die(mysql_error()); mysql_query("DELETE FROM player_items WHERE id = $use_id") or die(mysql_error()); } } } // produce and output the content for this page echo " <br/> <div class='profile-general-stats'> <table> <tr><th>Item Name</th><th>Description</th><th>Use/Sell</th></tr> "; $query = "SELECT * FROM player_items WHERE Username = '{$_SESSION['user']}' ORDER BY id ASC"; if(!$result = mysql_query($query)){ // query failed, handle the error here... die(mysql_error()); } else { // query worked without any errors if(!mysql_num_rows($result)){ // no matching rows echo " <tr> <td align='left' style='padding: 5px; padding-left: 25px;'>No Items</td> <td align='left' style='padding: 5px;'>No Items</td> <td align='middle' style='padding: 5px;'>No Items</td> </tr> "; } else { // at least one matching row while ($row = mysql_fetch_array($result)){ $item_id = $row['id']; $item_name = $row['Name']; $item_type = $row['Type']; $item_value = $row['Value']; $item_description = $row['Description']; $item_sell_value = $row['Sell_Price']; echo " <tr> <td align='left' style='padding: 5px; padding-left: 25px;'><strong>$item_name</strong></td> <td align='left' style='padding: 5px;'>$item_description</td> <td align='middle' style='padding: 5px;'><a href='?use&id=$item_id'>Use</a> | <a href='#sell_$item_name' id='$item_id'>Sell</a></td> </tr> "; } } } echo " </table> </div> "; ?> I'm pretty sure the 'automatically refresh' comment had to do with the need to click on the link again/refresh the page to get the updated database values to display, which will be be corrected by fixing the logic on the page as has been suggested, then quoted, and finally posted here...
  20. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343169.0
  21. You do realize that expr BETWEEN min AND max expects the min value to be less than the max value and -101.xxxx is less (a larger negative value) than -77.yyyy (you would need to reverse the order of the operands.)
  22. ^^^ Doing this will get your image data to be inserted into the table (just tested.) From the documentation for that function - It should read - You must use this function to send 'b' type (blob) data in a prepared statement, regardless of the size. If the total size of all the data in one query exceeds the size of max_allowed_packet setting, you can call this function multiple times to send the parameter data to the server in pieces (or chunks.)
  23. Also, your $db instance is not directly an instance of the mysqli class and could have something to do with the problem. Please post your db class. As already stated, you need to provide enough of your code that duplicates the problem. And as I have had to write in other threads, if the code you post isn't everything that someone would need to duplicate the problem, don't bother posting it, it is just a waste of your and our time.
  24. Slightly off-topic, but your prepare(), bind_param(), and close() statements should not be inside the foreach() loop. The foreach loop should be inside of the if($query = $db->connection->prepare("...."){ ... } statement. After you successfully prepare and bind the variables, you should loop over the data. The only thing that should be inside the foreach loop is the $query->execute(); statement and any error checking logic to test if the query had an error or not and if it inserted the row or not.
  25. Please use bbcode tags when posting code (using tags messes up all the white-space so that someone will be less likely to copy/test your code.)
×
×
  • 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.