Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,448
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. your select query is failing due to an sql (mysql) syntax error. you need to echo mysqli_error($con); to find out why. if i'm not mistaken, your food column contains strings and the $food variable/value needs to be enclosed in single quotes so that it is treated as a string - '$food'
  2. until you define what you mean by "multiple strings/keys" and then share that definition or a diagram with us, we cannot help you.
  3. your overall code, based on what you did post, has queries inside of loops inside of other loops... that's a bad design because - 1) running queries inside of loops take a lot longer than running a single query once. you can probably write one query using JOINs and simply have one loop to do everything you are trying to do. 2) it takes more code, so it is harder for you to see what your code is doing. without seeing what your code really is, best guess why you only get the last value is you are initializing that variable inside of the loop where that code is running and it is being set to zero every pass through the loop.
  4. don't give the user a choice on how to enter the date. use three specific select/option menus for the year, month, and day (add a date picker pop-up if desired to set the three select/option values.) then all you need to do is make sure the entered date is an actual date.
  5. i think you are making this harder than it is. if you are trying to sum value(s) that are present inside of your display loop, just initialize the total variable to zero before the start of the loop, add the value(s) to the total inside of the loop, and use the total after the end of the loop. specifically what values do you want to add up to make the grand total?
  6. your code is not testing if the upload worked before using the uploaded file. try this - if($_FILES['up']['error'] === 0){ // upload worked without any error $up=$_FILES['up']['name']; move_uploaded_file($_FILES['up']['tmp_name'],"upload"."/".$up); } else { // upload failed, do some debugging echo 'Upload failed.'; echo '<pre>'; print_r($_FILES); echo $_SERVER['CONTENT_LENGTH']; }
  7. @jazzman, i think your language translator is broken. the problem isn't the query. the OP can query for and retrieve the correct rows. the OP is making a QUIZ where the questions are displayed in a random order, without repeating a question.
  8. your post doesn't show what you mean by multiple strings/keys, so this is just a guess, but i suspect the answer involves arrays.
  9. http 500 responses from php scripts generally mean that your script had a fatal parse or fatal runtime error and didn't produce a complete response. in your case there's a fatal parse error because your the php statement on line 44/45 doesn't have a closing ; on it. please develop and debug php code with php's error_reporting set to E_ALL and display_errors set to ON so that php will help you. these settings must be in your php.ini to show parse errors in your main file. edit: once you fix that parse error, you have at least one more later in your code. TURN ON PHP'S ERROR_REPORTING/DISPLAY_ERRORS before you spend any more time trying to do this.
  10. what exactly don't you understand about the code that the comments don't explain?
  11. The form itself should be dynamically produced by looping over the $expected array. The $expected array may need to be expanded to hold unique information about each field, such as the field type.
  12. your first query grouped by the question. unless there are duplicate questions at any difficulty/topic, there's nothing to group. you second query is just numbering the questions in the query. the OP wants to randomize the display of the questions, so any numbering of the rows in the query would be out of order when displayed and has nothing to do with the stated problem.
  13. since you are storing the retrieved rows in an array, just use shuffle() to randomize the rows in that array, then loop over the shuffled/random array to output the questions. if ($ctr>0){ shuffle($arr); foreach($arr as $question){ echo $question; } } @jazzman, i don't know what you are reading in this thread, but the op has a number of questions for each difficulty/topic and wants to retrieve them and randomly output them. the problem is to output them without repeating any one question in a set.
  14. if you cannot find the correct one by examining the code, change each one to a different value - 'image1', 'image2' so that you can identify the correct one when it is output on the page. once you find the correct one and where in the code it is, you can find the filename variable (it will be fairly obvious since the filename variable is being used in the src=' ... ' attribute.)
  15. also, for mysqli_query(), the connection is the first parameter. The query is the second parameter. are you sure you are making a mysqli connection or is it a mysql connection?
  16. your table design is not workable, resulting in a huge amount of code that is hard to make work. store ONE piece of data per row. if you want to limit the number of rows to 5 for any condition, you manage that in your application.
  17. you would add a WHERE term to your query that either excludes the admins or selects everyone but admins, whichever is easier to do. edit, lol, see the above reply by jessica.
  18. your code has no error checking logic to get it to tell you where or why it might be failing. see the code in the following post for some pdo prepare/execute logic with error checking - http://forums.phpfreaks.com/topic/277964-using-mysql-and-php-to-extract-from-a-db/?do=findComment&comment=1429891
  19. for that specific query, you are expecting either zero or one row - if($row = $stmt->fetchobject()){ // query matched the one expected row } else { // query matched no row } i'm also pretty sure there is no pdo fetch_object() method either.
  20. input parameters can be supplied as an array in the execute() method (all values are treated as strings though.) other than the try/catch around the connection, your code has no error checking in it (the $pdo->connect_errno property doesn't exist and isn't doing anything.) i'm also pretty sure that there isn't an $stmt->num_rows property either. you would use the rowCount ( void ) method, when it exists (is usually better to just fetch/fetchall the rows and test if any rows were fetched. do you have php's error_reporting/display_errors turned full on so that php is helping you? you need to use logic like the following to check for errors - $dsn = "mysql:host=localhost;dbname=maindb"; $user = "root"; $password = "mypass"; try { $pdo = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } $query = " your query statement here "; if(!$stmt = $pdo->prepare($query)){ // prepare failed echo "<pre>Prepare failed:\n"; print_r($pdo->errorInfo()); echo "</pre>"; } else { if(!$stmt->execute(array($page))){ // execute failed echo "<pre>Execute failed:\n"; print_r($stmt->errorInfo()); echo "</pre>"; } else { // query ran without any errors, you can test if it returned any rows and use them here } }
  21. a basic while(){} loop can be used to do this as well.
  22. the suggestion to use a bootable linux cd wasn't to install linux, it was to boot to an environment where windows isn't running so that you can delete the file without it being locked by the windows operating system.
  23. did you try searching the source code for the offending alt='image' tag and change it to use the filename variable?
  24. you will also need to enclose customer_# column name in back-ticks as the # isn't normally permitted in an identifier - `customer_#`
  25. afaik, there's no direct equivalent to msyql_result, because it is so inefficient at what it does. you need to fetch the row and access the value. you can do this all at once using - list($count) = mysqli_fetch_row($query_run);
×
×
  • 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.