Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Deleter's Achievements


Newbie (1/14)



  1. Hello everyone! I recreated the script from chapter 11 about file compression exactly as it is in the book but it only backs up the first table from any database. Here's the code as it is in my IDE: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Database Backup</title> <link rel="stylesheet" href="style.css"> </head> <body> <?php # Script 11.1 - db_backup.php // Set the name of the database $db_name = 'testlogin'; // Make sure that the backup directory exists $dir = "backups/$db_name"; if (!is_dir($dir)) { if (!@mkdir($dir)) { die("<p>The backup directory--$dir--could not be created.</p></body></html>"); } } // Get the current time $time = time(); // Connect to the database $dbc = @mysqli_connect('localhost', 'root', 'pass', $db_name) OR die("<p>The database--$db_name--could not be backed up.</p></body></html>"); // Retreive the tables in this database $r = mysqli_query($dbc, 'SHOW TABLES') OR trigger_error("Error: " . mysqli_error($dbc)); // Confirm that at least one record was returned and print a message. No need to back-up an empty database! if (mysqli_num_rows($r) > 0) { echo "<p>Backing up database '$db_name'.</p>\n"; // Create a loop that fetches each table name while (list($table) = mysqli_fetch_array($r, MYSQLI_NUM)) { # Retrieve all the records from this table print_r($table); $q = "SELECT * FROM $table"; $r2 = mysqli_query($dbc, $q); // If the table contains some records, open the text file for writing if (mysqli_num_rows($r) > 0) { if ($fp = gzopen("$dir/{$table}_{$time}.sql.gz", 'w9')) { # Retrieve all of the table's data and write it to the file while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { foreach ($row as $value) { $value = addslashes($value); gzwrite($fp, "'$value', "); } gzwrite($fp, "\n"); } // End of WHILE loop. // Close the file and print a message to the browser gzclose($fp); echo "<p>Table '$table' backed up.</p>"; } else { echo "<p>The file--$dir/{$table}_{$time}.sql.gz--could not be opened for writing.</p>\n"; break; } // End of gzopen() IF. } // End of mysqli_num_rows() IF. } // End of WHILE loop. } else { echo "<p>The submitted database--$db_name--contains no tables.</p>\n"; } ?> I tried to print out the $table array and it contains only one element which is baffling since the given database has multiple tables. The query runs fine, so it can't be the cause of the problem. I'm really out of clues here as to what is going wrong. Any suggestions would be much appreciated! Thank you!
  2. Hi there! I encountered a problem within the view_cart.php script that has to do with the only input field - Quantity. When there's already something in the cart, the quantity can't be changed manually and after I press the Update My Cart button nothing changes and the already preset qty is again displayed. Here is the part of the script that in my opinion is problematic: 61 // Print the returned records 62 echo "\t<tr> 63 <td align=\"left\">{$row['artist']}</td> 64 <td align=\"left\">{$row['print_name']}</td> 65 <td align=\"right\">\${$_SESSION['cart'][$row['print_id']]['price']}</td> 66 <td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['print_id']}]\" value=\"{$_SESSION['cart'][$row['print_id']]['quantity']}\" /></td> 67 <td align\"right\">$" . number_format($subtotal, 2) . "</td> 68 </tr>\n"; My guess is that because the value argument is preset with the quantity coming from the session (line 66 of the script), nothing else can be entered into the qty field. Has anybody encountered the same issue? What would the work around be? Thank you for taking the time!
  • Create New...