sorin
-
Posts
29 -
Joined
-
Last visited
Posts posted by sorin
-
-
It's from ch17, from forum.php
I put it online so you can see it
http://www.viatasisanatatea.ro/ch17/forum.php
How come that you answer to this question but the one with the flags you didn't ? I asked for an idea not code.
<?php # Script 17.4 - forum.php // This page shows the threads in a forum. include ('includes/header.php'); // Retrieve all the messages in this forum... // If the user is logged in and has chosen a time zone, // use that to convert the dates and times: if (isset($_SESSION['user_tz'])) { $first = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')"; $last = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')"; } else { $first = 'p.posted_on'; $last = 'p.posted_on'; } // The query for retrieving all the threads in this forum, along with the original user, // when the thread was first posted, when it was last replied to, and how many replies it's had: $q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { // Create a table: echo '<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center"> <tr> <td align="left" width="50%"><em>' . $words['subject'] . '</em>:</td> <td align="left" width="20%"><em>' . $words['posted_by'] . '</em>:</td> <td align="center" width="10%"><em>' . $words['posted_on'] . '</em>:</td> <td align="center" width="10%"><em>' . $words['replies'] . '</em>:</td> <td align="center" width="10%"><em>' . $words['latest_reply'] . '</em>:</td> </tr>'; // Fetch each thread: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr> <td align="left"><a href="read.php?tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td> <td align="left">' . $row['username'] . '</td> <td align="center">' . $row['first'] . '</td> <td align="center">' . $row['responses'] . '</td> <td align="center">' . $row['last'] . '</td> </tr>'; print_r($row); } echo '</table>'; // Complete the table. } else { echo '<p>There are currently no messages in this forum.</p>'; } // Include the HTML footer file: include ('includes/footer.php'); ?>
-
Larry I tried to think how do do your example from ch17 with language flags, without users login, but is beyond my knowledge. This is my first example that I learn how to select language using the database and I want to learn it very well.
So I put 2 links with flags images but I'm not sure how and where to start .
Please give an idea.
This is the link where is the ch17 folder online:
http://www.viatasisanatatea.ro/ch17/forum.php
-
This is what I get from print_r using $row from while loop:
Array ( [thread_id] => 7 [subject] => Sample Thread [username] => troutster [responses] => 2 [last] => [first] => )
Can you tell me why?
-
In the header you put a default timezone,
$_SESSION['user_tz'] = 'America/New_York';
but can please tell me how to GET the real timezone?
My guess you have to get that on the login page, right?
I'm talking about a php function, if there is one, to get the timezone and not have it on database already.
-
There's a problem with your server or website, or with the URL itself. It has nothing to do with activate.php. If I go to this URL--
--I get the same server error.
Stupid me, I put .com instead of .ro .
Thank you Larry.
-
Larry this is the link that I have from email whern I clicked to activate the account:
Why I get server not foud?
-
A friend that knows js and php helped me. He told me this is Ajax.
After your answer and after his help, my question to you is: Can you, please, recommend me a js with php book?$(document).ready(function() { //var q = $('#categ_id').val(); $('.categ_id').on("change", function () { q = $(this).val(); $.ajax({ url: 'http://aproapetot.ro/ajax/get_subcateg.php', data: 'categ_id='+q, success: function (data) { $('#subcateg_id').html(data); } }).error(function() { alert ('An error occured'); }); }); });
<?php require_once ('../includes/mysql.inc.php'); $categ_id = (isset($_GET['categ_id'])&&is_numeric($_GET['categ_id']))?$_GET['categ_id']:die("The category is not set or it has a wrong value."); ?> <select name="subcategory"> <option>Select One</option> <?php $q = 'SELECT `subcategory_id`, `subcategory` FROM `subcategories` WHERE `category_id`='.$categ_id.' ORDER BY `subcategory` ASC'; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\">$row[1]</option>\n"; } ?>
-
Larry, on the add_page I have to have the categories, subcategories, title and description of the page. When I do the sql SELECT categories and bring in the select tag, then SELECT subcategories and bring in the select tag, I do that because I have to know from that a specific page belongs to an category and what subcategory.
So the database is in that way because when I do the insert
INSERT INTO pages (category_id, subcategory_id, title, content_page, user_id) VALUES ($cat, '$subcat', '$t', '$c', 1
I can't insert in pages only the category without the subcategory.
So this is the add_page live, of course I didn't put the css yet.
http://aproapetot.ro/add_page.php
In the left you can see all the categories that I brought from database. Those are jokes categories. So when I click on Bancuri(only in this I inserted) I will see the subcategories. Click on subcategory Albanezi an view the page.
So in the end you tell me not to put a subcategory Select tag? Because my question was about that tag not the database .
If it's like that, I am confused. I don't know how to do the insert then and secondly to do that 'route' on php pages:
categories->subcategories->view page
-
Having this database:
CREATE TABLE `categories` ( `category_id` SMALLINT NOT NULL AUTO_INCREMENT, `category` VARCHAR(30) NOT NULL, PRIMARY KEY (`category_id`), UNIQUE KEY `category` (`category`) ) ; CREATE TABLE `subcategories` ( `subcategory_id` SMALLINT NOT NULL AUTO_INCREMENT, `category_id` SMALLINT NOT NULL, `subcategory` VARCHAR(30) NOT NULL, PRIMARY KEY (`subcategory_id`), UNIQUE KEY `subcategory` (`subcategory`) ) ; CREATE TABLE `pages` ( `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, `category_id` SMALLINT UNSIGNED NOT NULL, `subcategory_id` SMALLINT UNSIGNED NOT NULL, `user_id` SMALLINT UNSIGNED NOT NULL, `title` VARCHAR(100) NOT NULL, `content_page` LONGTEXT NOT NULL, `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `category_id` (`category_id`), KEY `creation_date` (`date_created`) ); CREATE TABLE `users` ( `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `type` ENUM('member','admin', 'superadmin') NOT NULL, `username` VARCHAR(30) NOT NULL, `email` VARCHAR(80) NOT NULL, `pass` VARBINARY(32) NOT NULL, `first_name` VARCHAR(20) NOT NULL, `last_name` VARCHAR(40) NOT NULL, `date_expires` DATE NOT NULL, `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`) ) ;
I want to perform a second Select tag into the form. This second Select tag will bring the items from database, depending on the first Select. I am not sure how to do the sql WHERE for the second Select tag.
i hope you understand what I say. When I click on the first select and select on item, in the second select I want to have only the items related to the item_id that I selected.
So here is the add_page.php with the form and 2 select tags, from your book:
<?php require_once ('includes/config.inc.php'); require ('includes/form_functions.inc.php'); // Redirect non-administrators: //redirect_invalid_user('user_admin'); $page_title = 'Add a Site Content Page'; include ('includes/header.php'); // Require the database connection: //require(MYSQL); // Create an array for storing errors: $add_page_errors = array( ); // Validate the page title: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Validate the category: if (filter_var($_POST['category'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $cat = $_POST['category']; } else { $add_page_errors['category'] = 'Please select a category!'; } // Validate the subcategory: if (filter_var($_POST['subcategory'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $subcat = $_POST['subcategory']; } else { $add_page_errors['subcategory'] = 'Please select a subcategory!'; } // Validate the title: if (!empty($_POST['title'])) { $t = mysqli_real_escape_string($dbc, strip_tags($_POST['title'])); } else { $add_page_errors['title'] = 'Please enter the title!'; } // Validate the content: if (!empty($_POST['content_page'])) { $allowed = '<div><p><span><br><a><img><h1><h2><h3><h4><ul><ol><li><blockquote>'; $c = mysqli_real_escape_string($dbc, strip_tags($_POST['content_page'], $allowed)); } else { $add_page_errors['content_page'] = 'Please enter the content!'; } // If there are no errors, add the record to the database: if (empty($add_page_errors)) { // If everything's OK. $q = "INSERT INTO pages (category_id, subcategory_id, title, content_page, user_id) VALUES ($cat, '$subcat', '$t', '$c', 1)"; $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h4>The page has been added!</h4>'; $_POST = array( ); } else { // If it did not run OK. trigger_error('The page could not be added due to a system error. We apologize for any inconvenience.'); } } // End of $add_page_errors IF. } // End of the main form submission conditional. ?> <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Completeaza toate campurile:</legend> <p><label for="category"><strong>Categorie</strong></label><br /> <select name="category"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = "SELECT category_id, category FROM categories ORDER BY category ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['category']) && ($_POST['category'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p> <p><label for="subcategory"><strong>Subcategorie</strong></label><br /> <select name="subcategory"<?php if (array_key_exists('subcategory', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the subcategories and add to the pull-down menu: $q = "SELECT categories.category_id, categories.category, subcategories.subcategory_id, subcategories.category_id, subcategories.subcategory FROM categories INNER JOIN subcategories ON categories.category_id = subcategories.category_id ORDER BY subcategory ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['subcategory']) && ($_POST['subcategory'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('subcategory', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['subcategory'] . '</span>'; ?></p> <p><label for="title"><strong>Titlu</strong> </label><br /><?php create_form_input('title', 'text', $add_page_errors); ?></p> <p><label for="content_page"><strong>Continut</strong></label> <br /><?php create_form_input('content_page', 'textarea', $add_page_errors); ?></p> <p><input type="submit" name="submit_button" value="Adauga" id="submit_button" class="formbutton" /></p> </fieldset> </form> <?php include('includes/footer.php'); ?>
-
There is still an error. If you open a record to edit and you don't edit anything if you click submit you get this error:
The user could not be edited due to a system error. We apologize for any inconvenience.
Query: UPDATE users SET first_name='Melissa', last_name='Bank', email='melissa@authors.com' WHERE user_id=13 LIMIT 1
-
Same problem Lary like in the past. Friday I got the error, today when I check it again was working.
Now I know that when I get an error I will clean the history complete for all day.
-
I get this error:
The user could not be edited due to a system error. We apologize for any inconvenience. Query: UPDATE users SET first_name='John', last_name='Lennonn', email='john@beatles.com' WHERE user_id=3 LIMIT 1
And this is the page:
$page_title = 'Edit a User'; include ('includes/header.html'); echo '<h1>Edit a User</h1>'; // Check for a valid user ID, through GET or POST: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php $id = $_GET['id']; $id = $_GET['id']; } elseif ( (isset($_POST['id'])) &&(is_numeric($_POST['id'])) ) { // Form submission. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit( ); } require_once ('mysqli_connect.php'); // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array( ); // Check for a first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbc, trim($_POST['first_name'])); } // Check for a last 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'])); } // Check for an email address: 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)) { // If everything's OK. // Test for unique email address: $q = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id"; $r = @mysqli_query($dbc, $q) or die("Error: ".mysqli_error($dbc)) ; if (mysqli_num_rows($r) == 0) { // Make the query: $q = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q) or die("Error: ".mysqli_error($dbc)) ; if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<p>The user has been edited.</p>'; } else { // If it did not run OK. // Public message. 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>'; // Debugging message. } } else { // Already registered. echo '<p class="error">The email address has already been registered.</p>'; } } else { // Report the errors. echo '<p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // End of if (empty($errors)) IF. } // End of submit conditional. // Always show the form... // Retrieve the user's information: $q = "SELECT first_name, last_name, email FROM users WHERE user_id=$id"; $r = @mysqli_query ($dbc, $q) or die("Error: ".mysqli_error($dbc)) ; if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); // Create the form: 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 { // Not a valid user ID. echo '<p class="error">This page has been accessed in error.</p>'; } mysqli_close($dbc); include ('includes/footer.html');
-
i understand what you are saying but that means to make a lot of tables if jokes, short films, and stories will have each one a table. If I will have 10 categories that means 10 tables.
If I follow this idea will mean that each subcategory from jockes will have a diff table. What will happening if I will have subsubcategories.
A lot of tables.
If I don't understand exactly what you said please take a simple ex, or mine, and explain. Thank you.
-
I will show you a better example. Let's say that this is a site for jokes. I will have categories, that will be the menu as well: jokes, short films, stories. So these are the categories.
Now the subcategories will be for
jokes: sailors, plolice men, blondes, etc
shorts films: funny films, crazy films, wow films
stories: funny stories, wise stories
Subsubcategories
stories: funny stories: usa, canada, europe
Of course the list for categories and subcategories could be longer then what I put here.
So in this direction I made the tables:
CREATE TABLE `categories` (
`category_id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR(30) NOT NULL,
PRIMARY KEY (`category_id`),
UNIQUE KEY `category` (`category`)
) ;
CREATE TABLE `subcategories` (
`subcategory_id` SMALLINT NOT NULL AUTO_INCREMENT,`category_id` SMALLINT NOT NULL,
`subcategory` VARCHAR(30) NOT NULL,
PRIMARY KEY (`subcategory_id`),
UNIQUE KEY `subcategory` (`subcategory`)
) ;CREATE TABLE `subsubcategories` (
`subsubcategory_id` SMALLINT NOT NULL AUTO_INCREMENT,`subcategory_id` SMALLINT NOT NULL,
`subsubcategory` VARCHAR(30) NOT NULL,
PRIMARY KEY (`subsubcategory_id`),
UNIQUE KEY `subsubcategory` (`subsubcategory`)
) ;
CREATE TABLE `pages` (
`id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
`category_id` SMALLINT UNSIGNED NOT NULL,
`subcategory_id` SMALLINT UNSIGNED NOT NULL,
`user_id` SMALLINT UNSIGNED NOT NULL,
`title` VARCHAR(100) NOT NULL,
`content_page` LONGTEXT NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `category_id` (`category_id`),
KEY `creation_date` (`date_created`)
);
CREATE TABLE `users` (
`user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('member','admin', 'superadmin') NOT NULL,
`username` VARCHAR(30) NOT NULL,
`email` VARCHAR(80) NOT NULL,
`pass` VARBINARY(32) NOT NULL,
`first_name` VARCHAR(20) NOT NULL,
`last_name` VARCHAR(40) NOT NULL,
`date_expires` DATE NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ;Sometimes I will have subsubcategories, sometimes I will not have.
Please tell me if i designed the database corect.
-
Larry I want to understand very well join commands and in this direction I made a database to work with, but I'm not sure if I designed in in the right way. The example is cars.
table car_name:
car_id
car_nametable car_type:
type_id
car_id
car_typetable drivers:
driver_id
driver_nametable about_car:
id
car_id
type_id
driver_id
descriptionShould I put cars, car type and description in one table and driver separate or leave it how it is right now?
-
That example from the book that you recommended me is perfect. Thank you for thinking, back then, to put that chapter in the book. God bless you Larry.
-
Larry please tell me if you have any book where you explain how you can make a website to be multilingual.
I created a database, that I think that will work with what I want, but I'm not sure how to do the code .
CREATE TABLE `languages` ( `lang_id` tinyint(4) unsigned NOT NULL AUTO_INCREMENT, `lang_code` varchar(10) NOT NULL, `language` varchar(50) NOT NULL, PRIMARY KEY (`lang_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; INSERT INTO `languages` VALUES(1, 'ro', 'Romana'); INSERT INTO `languages` VALUES(2, 'en', 'English'); CREATE TABLE `pages` ( `page_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `identity` varchar(150) NOT NULL, PRIMARY KEY (`page_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; INSERT INTO `pages` VALUES(1, 'Home', 'index'); INSERT INTO `pages` VALUES(2, 'About us', 'about'); INSERT INTO `pages` VALUES(3, 'Services', 'services'); INSERT INTO `pages` VALUES(4, 'Testimonials', 'testimonials'); INSERT INTO `pages` VALUES(5, 'Contact us', 'contact'); INSERT INTO `pages` VALUES(6, 'Page not found!', 'error'); CREATE TABLE `pages_content` ( `page` int(11) unsigned NOT NULL, `language` tinyint(4) unsigned NOT NULL, `name` varchar(150) NOT NULL, `content` text, `meta_title` varchar(255) NOT NULL, `meta_description` varchar(255) NOT NULL, `meta_keywords` varchar(255) NOT NULL, PRIMARY KEY (`page`,`language`), KEY `language` (`language`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `users` ( `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `type` ENUM('member','admin') NOT NULL, `username` VARCHAR(30) NOT NULL, `email` VARCHAR(80) NOT NULL, `pass` VARBINARY(32) NOT NULL, `first_name` VARCHAR(20) NOT NULL, `last_name` VARCHAR(40) NOT NULL, `date_expires` DATE NOT NULL, `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I have the en and ro flags in a folder and I don't know how to make that switch that show flags images and change every time the content, when you change the flags.
-
Yes Larry the path was wrong. The correct one was
<script type="text/javascript" src="tinymce_3.5.11/tinymce/jscripts/tiny_mce/tiny_mce.js" ></script>
One more question about tinymce:
why the width doesn't work. I tried to put
tinyMCE.init({ // General options mode : "textareas", theme : "advanced", width : 300, plugins :
but doesn't work. Can you please give an idea?
http://www.aproapetot.ro/php-multi-language-site/contact.php
-
ReferenceError: tinyMCE is not defined.
On google I saw that means that the path is not good, but I took the path with browse from src.
-
I tried to put tinymce advanced but I don't see it on the page. The path is corect, because I selected with the "browse".
I don't know why doesn't work. This is the code that I put it on my site:
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php if (isset($page_title)) { echo $page_title; } else { echo 'Knowledge is Power'; } ?></title> <link rel="stylesheet" href="css/styles.css" type="text/css" /> <script type="text/javascript" src="../tinymce_3.5.11/tinymce/jscripts/tiny_mce/tiny_mce.js" ></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "advanced", plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", // Theme options theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true }); </script> </head> <body> <div id="container"> <div id="header"> <h1><a href="/">Orange</a></h1> <h2>multilingual cms</h2> <div class="clear"></div> </div> <div id="nav"> <ul> <?php // This array represents the main navigation items. The key for each element // is the text to be displayed on the tab $pages = array ( 'Home' => 'index.php', 'About' => 'about.php', 'Register' => 'register.php', 'Contact' => 'contact.php' ); /* If the user is viewing http://www.example.com/dir/file.php, then $_SERVER['PHP_SELF'] will have a value of /dir/file.php. To get just the file.php part of that, the basename( ) function is applied. */ $this_page = basename($_SERVER['PHP_SELF']); // Loop through each page foreach ($pages as $k => $v) { echo '<li'; // Add the class if it’s the current page: if ($this_page == $k) echo ' class="selected"'; echo '><a href="' . $v . '"><span>' . $k . '</span></a></li>'; } // End of FOREACH loop. ?> </ul> </div> <div id="body"> <div id="content">
-
Larry I have no idea what is happening with my computer.
5 min ago, before posting this I had the error from above. After I post the message I went back and tried again and worked . I appologise for this.
-
I put the folder with the files online and I saw that I can view the pdfs even I am not login.
On the localhost that was impossible because I was getting the error:
"You must be logged in as a registered user to view any of the PDFs listed below."
Why I have those differences online and localhost?
This is the link where I put the files:
-
That is strage. After I finished the category.php and page.php now works fine with admin without commenting that line .
-
Hello Larry,
I changed in phpmyadmin one username and I put ''admin" but when I login with the email and pass from admin I am still redirected and I can't get in.
If I comment this line
redirect_invalid_user('user_admin');
I can enter, but with that line I can't.
I don't know where is the error. I will put here the page code. Please give an idea.
<?php require_once ('includes/config.inc.php'); require ('includes/form_functions.inc.php'); // Redirect non-administrators: //redirect_invalid_user('user_admin'); $page_title = 'Add a Site Content Page'; include ('includes/header.html'); // Require the database connection: require(MYSQL); // Create an array for storing errors: $add_page_errors = array( ); // Validate the page title: if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['title'])) { $t = mysqli_real_escape_string($dbc, strip_tags($_POST['title'])); } else { $add_page_errors['title'] = 'Please enter the title!'; } // Validate the category: if (filter_var($_POST['category'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $cat = $_POST['category']; } else { $add_page_errors['category'] = 'Please select a category!'; } // Validate the description: if (!empty($_POST['description'])) { $d = mysqli_real_escape_string($dbc, strip_tags($_POST['description'])); } else { $add_page_errors['description'] = 'Please enter the description!'; } // Validate the content: if (!empty($_POST['content'])) { $allowed = '<div><p><span><br><a><img><h1><h2><h3><h4><ul><ol><li><blockquote>'; $c = mysqli_real_escape_string($dbc, strip_tags($_POST['content'], $allowed)); } else { $add_page_errors['content'] = 'Please enter the content!'; } // If there are no errors, add the record to the database: if (empty($add_page_errors)) { // If everything's OK. $q = "INSERT INTO pages (category_id, title, description, content) VALUES ($cat, '$t', '$d', '$c')"; $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h4>The page has been added!</h4>'; $_POST = array( ); } else { // If it did not run OK. trigger_error('The page could not be added due to a system error. We apologize for any inconvenience.'); } } // End of $add_page_errors IF. } // End of the main form submission conditional. ?> <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Fill out the form to add a page of content:</legend> <p><label for="first_name"><strong>Title</strong> </label><br /><?php create_form_input('title', 'text', $add_page_errors); ?></p> <p><label for="category"><strong>Category</strong></label><br /> <select name="category"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = "SELECT id, category FROM categories ORDER BY category ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['category']) && ($_POST['category'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p> <p><label for="description"><strong>Description</strong> </label><br /><?php create_form_input('description', 'textarea', $add_page_errors); ?></p> <p><label for="content"><strong>Content</strong></label> <br /><?php create_form_input('content', 'textarea', $add_page_errors); ?></p> <p><input type="submit" name="submit_button" value="Add This Page" id="submit_button" class="formbutton" /></p> </fieldset> </form> <?php include('includes/footer.html'); ?>
Chapter 12 View_User.php
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
This is the page from chapter 12 with view users. If in the database I have a lot of users and I want to put them for example each 10 users on a column and to make 2-3-4 columns how can I do that?
Like this:
foo foo foo
foo foo foo
foo foo foo
foo foo foo
ect