Jump to content
Larry Ullman's Book Forums

skeery2605

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by skeery2605

  1. Sorry about the confusion. I'm wanting to use the mysqli_oop_connect.php file for my DB connection instead of the way it tells me in 16.4. which is -----> $mysqli = new MySQLi('localhost', 'username', 'password', 'forum'); I'm not sure how to do it or if it is possible.
  2. In the 13.6 & 16.4 scripts it requires a DB connection using 13.6---> $dbc = mysqli_connect ('localhost', 'username', 'password', 'forum'); 16.4---> $mysqli = new MySQLi('localhost', 'username', 'password', 'forum'); is there any way i could make it use the mysqli_oop_connect.php instead? I'm in school and i dont like having my DB username & password on my screen like that where anybody could see it.
  3. I figured the problem i was having out.. i had to read the 13.3 again to see it. i had to enable the fileinfo.dll in the php.ini file. Everything works fine now. thanks for the help
  4. I cant get the uploader to work. I get the same error with my file or the downloadable file. Fatal error: Call to undefined function finfo_open() in C:\xampp\htdocs\lessons\chapter_13\upload_rtf.php on line 17 <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Upload a RTF Document</title> </head> <body> <?php # Script 13.3 upload_rtf.php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_FILES['upload']) && file_exists($_FILES['upload']['tmp_name'])) { $fileinfo = finfo_open(FILEINFO_MIME_TYPE); if (finfo_file($fileinfo, $_FILES['upload']['tmp_name']) == 'text/rtf') { echo '<p><em>The file would be acceptable!</em></p>'; unlink($_FILES['upload']['tmp_name']); } else { // invalid type echo '<p style="font-weight: bold; color: #C00">Please upload an RTF Document.</p>'; } finfo_close($fileinfo); } } ?> <form enctype="multipart/form-data" action="upload_rtf.php" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="524288" /> <fieldset> <legend>Select an RTF document of 512KB or smaller to be uploaded:</legend> <p><b>File:</b><input type="file" name="upload" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> </body> </html>
  5. i cant use the edit button. i get "this page has been accessed in error" ive went over my code multiple times and cant seem to find any errors. ive also use the edit_users.php in the downloadable files for the book and i still get the same result. im not sure how to fix it... My CODE <?php # Script 10.3 - edit_user.php $page_title = 'Edit a User'; include ('includes/header.html'); echo '<h1>Edit a User</h1>'; if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { $id = $_POST['id']; } else { echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } require_once ('mysqli_connect.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbc, trim($_POST['first_name'])); } if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = mysqli_real_escape_string($dbc, trim($_POST['last_name'])); } if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = mysqli_real_escape_string($dbc, trim($_POST['email'])); } if (empty($errors)) { $q = "SELECT user_id FROM users WHERE email='$e' AND user_id= != $id"; $r = @mysqli_query($dbc, $q); if (mysqli_num_rows($r) ==0) { $q = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { echo '<p>The user has been edited.</p>'; } else { echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; } } else { echo '<p class="error">The email address has already been registered.</p>'; } } else { echo '<p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } } // End of submit conditional. $q = "SELECT first_name, last_name, email FROM users WHERE user_id=$id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { $row = mysqli_fetch_array ($r, MYSQLI_NUM); echo '<form action="edit_user.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="' . $row[0] . '" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="60" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { echo '<p class="error">This page has been accessed in error.</p>'; } mysqli_close($dbc); include ('includes/footer.html'); ?>
  6. Ive got it going now. I missed two comma. i looked over them everytime i was looking to find errors
  7. Im having trouble the script running correctly. Im getting one error on two different lines. Everything seems to be correct. This the error Im getting on line 50 and 63. (lines with errors highlighted in red) mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in.[/size] <?php # Script 10.4 - view_users.php #4 $page_title = 'View the Current Users'; include ('includes/header.html'); echo '<h1>Registered Users</h1>'; require_once ('mysqli_connect.php'); $display = 10; if (isset($_GET['p']) && is_numeric($_GET['p'])) { $pages = $_GET['p']; } else { $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; if ($records > $display) { // More than one page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. if (isset($_GET['s']) && is_numeric ($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y) AS dr user_id FROM users ORDER BY registration_date ASC LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b>Last Name</b></td> <td align="left"><b>First Name</b></td> <td align="left"><b>Date Registered</b></td> </tr>'; $bg = '#eeeeee'; while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php"?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } echo '</table>'; mysqli_free_result($r); mysqli_close($dbc); if ($pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; if ($current_page !=1) { echo '<a href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> '; } for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } if ($current_page != $pages) { echo '<a href="view_users.php?s=' . ($start = $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; } // End of Link Section. include ('includes/footer.html'); ?>
  8. Its been awhile since i was on here.. im still not able to get my timezone loaded im not sure how to do it at all.. im just starting in php and mysql. so chapters 1-6 in this book is as much as i now about it. if theres something i can do to get it working.
  9. mysql> SELECT message_id, subject, CONVERT_TZ(date_entered, 'UTC', 'America/New_York') AS local -> FROM messages ORDER BY date_entered DESC LIMIT 1; +---------------+---------------+-------+ | message_id | subject | local | +---------------+---------------+-------+ | 5 | PHP Errors | NULL | +---------------+--------------+--------+ 1 row in set (0.00 sec)
  10. I added all the code from the chapter until I get the problem.. I made the code red where i get the problem.. the book says if I get a null result the names of my timezones are wrong or mysql hasnt loaded timezones. CREATE DATABASE forum CHARACTER SET utf8 COLLATE utf8_general_ci; USE forum; CREATE TABLE forums ( forum_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(60) NOT NULL, PRIMARY KEY (forum_id), UNIQUE (name) ) ENGINE = INNODB; CREATE TABLE messages ( message_id INT UNSIGNED NOT NULL AUTO_INCREMENT, parent_id INT UNSIGNED NOT NULL DEFAULT 0, forum_id TINYINT UNSIGNED NOT NULL, user_id MEDIUMINT UNSIGNED NOT NULL, subject VARCHAR(100) NOT NULL, body LONGTEXT NOT NULL, date_entered DATETIME NOT NULL, PRIMARY KEY (message_id), INDEX (parent_id), INDEX (forum_id), INDEX (user_id), INDEX (date_entered) ) ENGINE = MYISAM; CREATE TABLE users ( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(30) NOT NULL, pass CHAR(40) NOT NULL, first_name VARCHAR(20) NOT NULL, last_name VARCHAR(40) NOT NULL, email VARCHAR(60) NOT NULL, PRIMARY KEY (user_id), UNIQUE (username), UNIQUE (email), INDEX login (pass, email) ) ENGINE = INNODB; CHARSET utf8; INSERT INTO forums (name) VALUES ('MySQL'), ('PHP'), ('Sports'), ('HTML'), ('CSS'), ('Kindling'); INSERT INTO forums (name) VALUES ('Modern Dance'); INSERT INTO users (username, pass, first_name, last_name, email) VALUES ('troutster', SHA1('mypass'), 'Larry', 'Ullman', 'lu@example.com'), ('funny man', SHA1('monkey'), 'David', 'Brent', 'db@example.com'), ('Gareth', SHA1('asstmgr'), 'Gareth', 'Keenan', 'gk@example.com'); INSERT INTO users (username, pass, first_name, last_name, email) VALUES ('tim', SHA1( 'psych' ) , 'Tim', 'Canterbury', 'tc@example.com'), ('finchy', SHA1('jerk'), 'Chris', 'Finch', 'cf@example.com'); SELECT * FROM forums; SELECT user_id, username FROM users; INSERT INTO messages (parent_id, forum_id, user_id, subject, body, date_entered) VALUES (0, 1, 1, 'Question about normalization.', 'I''m confused about normalization. For the second normal form (2NF), I read...', UTC_TIMESTAMP()), (0, 1, 2, 'Database Design', 'I''m creating a new database and am having problems with the structure. How many tables should I have?...', UTC_TIMESTAMP()), (2, 1, 2, 'Database Design', 'The number of tables your database includes...', UTC_TIMESTAMP()), (0, 1, 3, 'Database Design', 'Okay, thanks!', UTC_TIMESTAMP()), (0, 2, 3, 'PHP Errors', 'I''m using the scripts from Chapter 3 and I can''t get the first calculator example to work. When I submit the form...', UTC_TIMESTAMP()); SELECT message_id, subject, date_entered FROM messages ORDER BY date_entered DESC LIMIT 1; SELECT message_id, subject, CONVERT_TZ(date_entered, 'UTC', 'America/New_York') AS local FROM messages ORDER BY date_entered DESC LIMIT 1;
  11. When i do step 8 i get a null result for local.. ive tried it multple time and i only get the null result
  12. Im just starting in PHP and SQL fourth edition and it tells me to not use notepad for writing code. i use a program called notepad++. I know its not the same as regular notepad. Is notepad++ ok to use?
×
×
  • Create New...