Jump to content

noobtopro

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Posts posted by noobtopro

  1. Quesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way.

     

    First set up everything for DB:

     

    <?php

    //connect to MySQL

    $db = mysql_connect('localhost', 'root', '000') or

        die ('Unable to connect. Check your connection parameters.');

     

    //create the main database if it doesn't already exist

    $query = 'CREATE DATABASE IF NOT EXISTS moviesite';

    mysql_query($query, $db) or die(mysql_error($db));

     

    //make sure our recently created database is the active one

    mysql_select_db('moviesite', $db) or die(mysql_error($db));

     

    //create the movie table

    $query = 'CREATE TABLE movie (

            movie_id        INTEGER UNSIGNED  NOT NULL AUTO_INCREMENT,

            movie_name      VARCHAR(255)      NOT NULL,

            movie_type      TINYINT          NOT NULL DEFAULT 0,

            movie_year      SMALLINT UNSIGNED NOT NULL DEFAULT 0,

            movie_leadactor INTEGER UNSIGNED  NOT NULL DEFAULT 0,

            movie_director  INTEGER UNSIGNED  NOT NULL DEFAULT 0,

     

            PRIMARY KEY (movie_id),

            KEY movie_type (movie_type, movie_year)

        )

        ENGINE=MyISAM';

    mysql_query($query, $db) or die (mysql_error($db));

     

    //create the movietype table

    $query = 'CREATE TABLE movietype (

            movietype_id    TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,

            movietype_label VARCHAR(100)    NOT NULL,

            PRIMARY KEY (movietype_id)

        )

        ENGINE=MyISAM';

    mysql_query($query, $db) or die(mysql_error($db));

     

    //create the people table

    $query = 'CREATE TABLE people (

            people_id        INTEGER UNSIGNED    NOT NULL AUTO_INCREMENT,

            people_fullname  VARCHAR(255)        NOT NULL,

            people_isactor    TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,

            people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,

     

            PRIMARY KEY (people_id)

        )

        ENGINE=MyISAM';

    mysql_query($query, $db) or die(mysql_error($db));

     

    echo 'Movie database successfully created!';

    ?>

     

     

     

    ********************************************************************

    ***********************************************************************

     

    second file to load info into DB:

     

     

     

    <?php

    // connect to MySQL

    $db = mysql_connect('localhost', 'root', '000') or

        die ('Unable to connect. Check your connection parameters.');

     

    //make sure you're using the correct database

    mysql_select_db('moviesite', $db) or die(mysql_error($db));

     

    // insert data into the movie table

    $query = 'INSERT INTO movie

            (movie_id, movie_name, movie_type, movie_year, movie_leadactor,

            movie_director)

        VALUES

            (1, "Bruce Almighty", 5, 2003, 1, 2),

            (2, "Office Space", 5, 1999, 5, 6),

            (3, "Grand Canyon", 2, 1991, 4, 3)';

    mysql_query($query, $db) or die(mysql_error($db));

     

    // insert data into the movietype table

    $query = 'INSERT INTO movietype

            (movietype_id, movietype_label)

        VALUES

            (1,"Sci Fi"),

            (2, "Drama"),

            (3, "Adventure"),

            (4, "War"),

            (5, "Comedy"),

            (6, "Horror"),

            (7, "Action"),

            (8, "Kids")';

    mysql_query($query, $db) or die(mysql_error($db));

     

    // insert data into the people table

    $query  = 'INSERT INTO people

            (people_id, people_fullname, people_isactor, people_isdirector)

        VALUES

            (1, "Jim Carrey", 1, 0),

            (2, "Tom Shadyac", 0, 1),

            (3, "Lawrence Kasdan", 0, 1),

            (4, "Kevin Kline", 1, 0),

            (5, "Ron Livingston", 1, 0),

            (6, "Mike Judge", 0, 1)';

    mysql_query($query, $db) or die(mysql_error($db));

     

    echo 'Data inserted successfully!';

    ?>

     

     

     

    **************************************************************

    ****************************************************************

     

    MY CODE FOR THE QUESTION:

     

     

    <?php

    $db = mysql_connect('localhost', 'root', '000') or

    die ('Unable to connect. Check your connection parameters.');

     

    mysql_select_db('moviesite', $db) or die(mysql_error($db));

     

    //get our starting point for the query from the URL

    if (isset($_GET['offset'])) {

    $offset = $_GET['offset'];

    } else {

    $offset = 0;

    }

     

    //get the movie

    $query  = 'SELECT

    movie_name, movie_year

    FROM

    movie

    ORDER BY

    movie_name

    LIMIT ' . $offset . ' , 1';

    $result = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_fetch_assoc($result);

    ?>

    <html>

    <head>

    <title><?php echo $row['movie_name']; ?></title>

    </head>

    <body>

    <table border = "1">

    <tr>

    <th>Movie Name</th>

    <th>Year</th>

    </tr><tr>

    <td><?php echo $row['movie_name']; ?></td>

    <td><?php echo $row['movie_year']; ?></td>

    </tr>

    </table>

    <p>

    <a href="page.php?offset=0">Page 1</a>,

    <a href="page.php?offset=1">Page 2</a>,

    <a href="page.php?offset=2">Page 3</a>

    </p>

    </body>

    </html>

     

     

  2. Thanks guys, here is what I came up with based on your advice. I believe it works:

     

     

    <?php

    setcookie('font', $_POST['font'], time() + 60);

    setcookie('size', $_POST['size'], time() + 60);

    setcookie('color', $_POST['color'], time() + 60);

    //setting cookies must be the first thing before any whitespace of any html or anything at all.

     

    $_COOKIE['font'] = $_POST['font'];

    $_COOKIE['size'] = $_POST['size'];

    $_COOKIE['color'] = $_POST['color'];

     

    session_start();

    $_SESSION['textformat'] = $_POST['textformat'];

    $_SESSION['font'] = $_POST['font'];

    $_SESSION['size'] = $_POST['size'];

    $_SESSION['color'] = $_POST['color'];

     

     

     

     

    // Turn off all error reporting

    error_reporting(0);

     

    // Report simple running errors

    error_reporting(E_ERROR | E_WARNING | E_PARSE);

     

    // Reporting E_NOTICE can be good too (to report uninitialized

    // variables or catch variable name misspellings ...)

    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

     

    // Report all errors except E_NOTICE

    // This is the default value set in php.ini

    error_reporting(E_ALL ^ E_NOTICE);

     

    // Report all PHP errors (see changelog)

    error_reporting(E_ALL);

     

    // Report all PHP errors

    error_reporting(-1);

     

    // Same as error_reporting(E_ALL);

    ini_set('error_reporting', E_ALL);

     

    ?>

     

     

     

    <?php

     

     

     

    if (isset($_POST['save_prefs'])) {

     

     

    echo '<html>';

    echo '<head>';

    echo '<title>here it is</title>';

    echo '</head>';

    echo '<body>';

    echo '<p';

     

    echo ' style="font-family: ' . $_COOKIE['font'] . '; ';

    echo 'font-size: ' . $_COOKIE['size'] . '; ';

    echo 'color: ' . $_COOKIE['color'] . ';" ';

    echo '>';

     

    echo $_POST['textformat'];

     

    echo '</p>';

     

    //just to check to see if the comp is inside the if statement

    echo $_COOKIE['font'];

    echo $_COOKIE['size'];

    echo $_COOKIE['color'];

     

    }

     

    else {

     

     

     

    echo '<html>';

    echo '<head>';

    echo '</head>';

    echo '<body>';

    echo '<p';

     

    echo ' style="font-family: ' . $_SESSION['font'] . '; ';

    echo 'font-size: ' . $_SESSION['size'] . '; ';

    echo 'color: ' . $_SESSION['color'] . ';" ';

    echo '>';

     

    echo $_SESSION['textformat'];

     

    echo '</p>';

     

    }

    ?>

     

    </body>

    </html>

  3. Hello again everyone,

                                    I know someone knows how to do this.

     

    Question: In the program you created in question 4, allow your user the option of saving the information for the next time they visit. If they choose "yes", save information in a cookie.

     

    1st part of Question (I have done): Created a text input with options to select font family, font size, and font color.

     

    At the bottom of question5.php I added a checkbox to save the information. I then created an if statement on the processing page (question5display.php. I would appreciate some help, thanks guys.

     

    Here is the form ( called it question5.php):

     

    <html>

    <head>

    <title>

    Please Enter Your Text</title>

    </head>

     

    <body>

     

     

     

    <form method="post" action="question5display.php">

     

    <p>Enter the text you want formatted please:

     

    <input type="text" name="textformat" maxlength="30" size="30" />

     

    <table>

    <tr>

      <td><label for="font">Select Font:</label></td>

      <td><select id="font" name="font">

      <option value="Verdana">Verdana</option>

      <option value="Arial">Arial</option>

      <option value="Times New Roman">Times New Roman</option>

    </select>

    </td>

    </tr>

     

    <tr>

      <td><label for ="size">Select Size:</label></td>

      <td><select id="size" name="size">

      <option value="10px">10px</option>

      <option value="12px">12px</option>

      <option value="14px">14px</option>

      <option value="20px">20px</option>

     

    </select>

    </td>

    </tr>

     

    <tr>

      <td><label for="color">Select Color:</label></td>

      <td><select id="color" name="color">

      <option value="green">Green</option>

      <option value="blue">Blue</option>

      <option value="red">Red</option>

      </select>

    </td>

    </tr>

     

     

    </table>

     

    <input type="checkbox" id="save_prefs" name="save_prefs" />

    <label for="save_prefs">Save these preferences for the next time you log in.</label>

     

      <input type="submit" name="submit" value="Submit" />

    </form>

     

     

    </body>

    </html>

     

     

     

     

     

     

    Here is the page it goes to (called it question5display):

     

     

     

    <?php

     

    if (isset($_POST['save_prefs'])) {

      setcookie('font', $_POST['font'], time() + 60);

      setcookie('size', $_POST['size'], time() + 60);

      setcookie('color', $_POST['color'], time() + 60);

     

      $_COOKIE['font'] = $_SESSION['font'];

      $_COOKIE['size'] = $_SESSION['size'];

      $_COOKIE['color'] = $_SESSION['color'];

     

     

    }

     

     

    session_start();

    $_SESSION['textformat'] = $_POST['textformat'];

    $_SESSION['font'] = $_POST['font'];

    $_SESSION['size'] = $_POST['size'];

    $_SESSION['color'] = $_POST['color'];

     

     

    ?>

     

     

    <html>

    <head>

    </head>

    <body>

    <p

    <?php

    echo ' style="font-family: ' . $_SESSION['font'] . '; ';

    echo 'font-size: ' . $_SESSION['size'] . '; ';

    echo 'color: ' . $_SESSION['color'] . ';" ';

    ?>>

    <?php

    echo $_SESSION['textformat'];

    ?>

    </p>

     

     

    </body>

    </html>

  4. Hello again everyone,

                                      I am new to PHP. This is the second part of a question:

     

    Question: In the program you created in question 4, allow your user the option of saving the information for the next time they visit. If they choose "yes", save information in a cookie.

     

    At the bottom of question5.php I added a checkbox to save the information. I then created an if statement on the processing page (question5display.php. I would appreciate some help, thanks guys.

     

    Here is the form ( called it question5.php):

     

    <html>

    <head>

    <title>

    Please Enter Your Text</title>

    </head>

     

    <body>

     

     

     

    <form method="post" action="question5display.php">

     

    <p>Enter the text you want formatted please:

     

    <input type="text" name="textformat" maxlength="30" size="30" />

     

    <table>

    <tr>

    <td><label for="font">Select Font:</label></td>

    <td><select id="font" name="font">

    <option value="Verdana">Verdana</option>

    <option value="Arial">Arial</option>

    <option value="Times New Roman">Times New Roman</option>

    </select>

    </td>

    </tr>

     

    <tr>

    <td><label for ="size">Select Size:</label></td>

    <td><select id="size" name="size">

    <option value="10px">10px</option>

    <option value="12px">12px</option>

    <option value="14px">14px</option>

    <option value="20px">20px</option>

     

    </select>

    </td>

    </tr>

       

    <tr>

    <td><label for="color">Select Color:</label></td>

    <td><select id="color" name="color">

    <option value="green">Green</option>

    <option value="blue">Blue</option>

    <option value="red">Red</option>

    </select>

    </td>

    </tr>

     

       

    </table>

     

    <input type="checkbox" id="save_prefs" name="save_prefs" />

    <label for="save_prefs">Save these preferences for the next time you log in.</label>

     

    <input type="submit" name="submit" value="Submit" />

    </form>

     

     

    </body>

    </html>

     

     

     

     

     

     

    Here is the page it goes to (called it question5display):

     

     

     

    <?php

     

    if (isset($_POST['save_prefs'])) {

    setcookie('font', $_POST['font'], time() + 60);

    setcookie('size', $_POST['size'], time() + 60);

    setcookie('color', $_POST['color'], time() + 60);

     

    $_COOKIE['font'] = $_SESSION['font'];

    $_COOKIE['size'] = $_SESSION['size'];

    $_COOKIE['color'] = $_SESSION['color'];

     

     

    }

     

     

    session_start();

    $_SESSION['textformat'] = $_POST['textformat'];

    $_SESSION['font'] = $_POST['font'];

    $_SESSION['size'] = $_POST['size'];

    $_SESSION['color'] = $_POST['color'];

     

     

    ?>

     

     

    <html>

    <head>

    </head>

    <body>

    <p

    <?php

    echo ' style="font-family: ' . $_SESSION['font'] . '; ';

    echo 'font-size: ' . $_SESSION['size'] . '; ';

    echo 'color: ' . $_SESSION['color'] . ';" ';

    ?>>

    <?php

    echo $_SESSION['textformat'];

    ?>

    </p>

     

     

    </body>

    </html>

  5. Hello Everyone,

                          I am a noob at PHP so please forgive me if my code is wrong. I have a strong understanding of HTML and CSS  just for the curious.

     

    Question: Write a program that formats a block of text (to be input by the user) based on preferences chosen by the user. Give your user options for color of text, font choice and size. Display output on a new page. I would greatly appreciate someone's help. The text is showing up but not according to the options selected. I know there is something wrong with the output page.

     

    Here is the Input Page (call it question4.php):

     

    <html>

    <head>

    <title>

    Please Enter Your Text</title>

    </head>

     

    <body>

     

     

     

    <form method="post" action="question4display.php">

     

    <p>Enter the text you want formatted please:

     

    <input type="text" name="textformat" maxlength="30" size="30" />

     

    <table>

    <tr>

    <td><label for="font">Select Font:</label></td>

    <td><select id="font" name="font">

    <option value="Verdana">Verdana</option>

    <option value="Arial">Arial</option>

    <option value="Times New Roman">Times New Roman</option>

    </select>

    </td>

    </tr>

     

    <tr>

    <td><label for ="size">Select Size:</label></td>

    <td><select id="size" name="size">

    <option value="10px">10px</option>

    <option value="12px">12px</option>

    <option value="14px">14px</option>

    <option value="20px">20px</option>

     

    </select>

    </td>

    </tr>

       

    <tr>

    <td><label for="color">Select Color:</label></td>

    <td><select id="color" name="color">

    <option value="green">Green</option>

    <option value="blue">Blue</option>

    <option value="red">Red</option>

    </select>

    </td>

    </tr>

    </table>

     

    <input type="submit" name="submit" value="Submit" />

    </form>

     

     

    </body>

    </html>

     

     

     

     

    Here is the OUTPUT page (called it:question4display.php):

     

     

    <?php

     

    session_start();

    $_SESSION['textformat'] = $_POST['textformat'];

    $_SESSION['font'] = $_POST['font'];

    $_SESSION['size'] = $_POST['size'];

    $_SESSION['color'] = $_POST['color'];

     

    ?>

     

    <html>

    <head>

    </head>

    <body>

    <p

    <?php

    echo ' style="font-family: ' . $_POST['font'] . '; ';

    echo 'font-size: ' . $_POST['size'] . '; ';

    echo 'color: ' . $_POST['color'] . '; ';

    ?> >

    <?php

    echo $_POST['textformat'];

    ?>

    </p>

     

    </body>

    </html>

     

     

     

×
×
  • 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.