Jump to content
Larry Ullman's Book Forums

sorin

Members
  • Posts

    29
  • Joined

  • Last visited

Posts posted by sorin

  1. 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

    <?php 
    
    $page_title = 'View the Current Users';
    include ('includes/header.php');
    echo '<h1>Registered Users</h1>';
    
    require ('mysqli_connect.php');
    		
    // Define the query:
    $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY registration_date ASC";		
    $r = @mysqli_query ($dbc, $q) or die("Error: ".mysqli_error($dbc));
    
    // Count the number of returned rows:
    $num = mysqli_num_rows($r);
    
    if ($num > 0) { // If it ran OK, display the records.
    
    	// Print how many users there are:
    	echo "<p>There are currently $num registered users.</p>\n";
    
    	// Table header:
    	echo '<table align="center" cellspacing="3" cellpadding="3" 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>
    ';
    	
    	// Fetch and print all the records:
    	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
    		echo '<tr>
    			<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);	
    
    } else { // If no records were returned.
    	echo '<p class="error">There are currently no registered users.</p>';
    }
    
    mysqli_close($dbc);
    
    include ('includes/footer.html');
    ?>
    
  2. 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');
    ?>
    
  3. 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

     

  4. 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";
            }
    ?>
    
  5. 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

  6. 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');
    ?>
    
    
    
    
  7. 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');
    

     

  8. 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.

  9. 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.

  10. 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_name

     

     

    table car_type:
    type_id
    car_id
    car_type

     

     

    table drivers:
    driver_id
    driver_name

     

     

    table about_car:
    id
    car_id
    type_id
    driver_id
    description

     

    Should I put cars, car type and description in one table and driver separate or leave it how it is right now?

  11. 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.

  12. 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

  13. 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">
    
  14. 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:

    http://aproapetot.ro/e-commerce/index.php

  15. 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');
    ?>
    
    
    
    
×
×
  • Create New...