Jump to content
Larry Ullman's Book Forums

selliottsxm

Members
  • Posts

    32
  • Joined

  • Last visited

Posts posted by selliottsxm

  1. I'm still doing it wrong, am I using the mysqli_query function incorrectly?

     

    Tried this:

     

    require_once ('../mysqli_connect.php');
    $movie_id = $_GET['movie_id'];
    $q = mysqli_query("SELECT * FROM movies WHERE movie_id = $movie_id");
    $r = mysqli_query($q, $dbc);
     

     

    Got this:

     

    PHP Warning:  mysqli_query() expects at least 2 parameters, 1 given in /Applications/MAMP/htdocs/movie2.php on line 29

     

    PHP Warning:  mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/movie2.php on line 30
     

  2. Still getting errors.  Here I am right now (I'll only include the relevant part and then the error

     

    require_once ('../mysqli_connect.php');
    $movie_id = $_GET['movie_id'];
    $q = "SELECT * FROM movies WHERE movie_id = $movie_id";
    $r = mysqli_fetch_array ($dbc, $q);


    echo
    '<table cols="2" width="1100px" align="center">
    <tr>
    <td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td>
    <td></td>
    </tr>
    <tr>
    <td align="center" width="960px">
     

     

    ERROR IS:

     

    PHP Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in /Applications/MAMP/htdocs/movie2.php on line 30  (Line 30 is $r)
     

  3. Hello,

     

    I am trying, without success I might add, to execute a simple query.  One variable is passed as a $_GET value which is movie_id.  I defined a variable $movie_id = $_GET['movie_id'];

     

    I then wrote a query: SELECT * FROM movies WHERE movie_id = $movie_id

     

    I'll paste the relevant script below. 

     

    require_once ('../mysqli_connect.php');
    $movie_id = $_GET['movie_id'];
    $q = mysqli_query("SELECT * FROM movies WHERE movie_id = '$movie_id'");
    $r = mysqli_fetch_array ($dbc, $q);


    echo '
    <table cols="2" width="1100px" align="center">
    <tr>
    <td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td>
    <td></td>
    </tr>
    <tr>
    <td align="center" width="960px">

     

    Can anyone help?
     

  4. I am having a devil of a time with joining up my tables.  I have 7 tables:

     

    movies, studios,scenes are all joining up fine using this query:

     

    SELECT movies.movie_id, movies.movie_title, movies.movie_desc, studio, scene_name FROM movies INNER JOIN studios ON movies.studio_id=studios.studio_id INNER JOIN scenes ON movies.movie_id=scenes.movie_id ORDER BY movie_id ASC, scene_name ASC

     

    i am trying to join up the remaining four which is where I am having problems.

     

    The tables are:

     

    actors

    movie_actor (movie_actor being the child and related to movies by the movie_id

     

    genres

    movie_genres (movie_genres being the child and related to movies by the movie_id

     

    I have tried joining up actors and genres.  In the query below I tried with the  genres table, then tried with the actors table. The error result is the same with the exception of the field name:

     

    SELECT movies.movie_id, movies.movie_title, movies.movie_desc, studio, scene_name, genre FROM movies INNER JOIN studios ON movies.studio_id=studios.studio_id INNER JOIN scenes ON movies.movie_id=scenes.movie_id
    INNER JOIN movie_genres ON movies.movie_id=movie_genres.movie_id ORDER BY movie_id ASC, scene_name ASC

     

    returns an error: unknown column 'genre' in the field list.

     

    Does anyone know what I might be doing wrong?

     

     

  5. I'm trying to display the results of a query in a table.  The query returns graphic file names so that I can display images in a table.  I'm trying to display them so that there are four images in one row, but all I get is one per row.  Does anyone know what I might try?

     

    My script is below:

     

    <?php
    # feeds_user.php  This script will advertise the feeds on the index.php page (page for non members)

    require_once ('../mysqli_connect.php');

    $q= "SELECT feed_id, feed_graphic AS graphic FROM feeds_user ORDER By feed_id";
    $r= @mysqli_query ($dbc, $q);

    while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)){


    echo '<table align="center" cellspacing="0" cellpaddin g="5" border="10" width="1100px">
    <tr> .
        <td align="center" colspan="4"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td>
    </tr>'
    ;
    }
    echo
    '</table>';


    ?>
     

  6. I am having trouble getting this to work.  I have a table in my database which contains graphics I need to use in a table. So I want to create a query and array to populate the table.  My php is below.  Can anyone see what I'm doing wrong?

     

    <?php
    # feeds_user.php  This script will advertise the feeds on the index.php page (page for non members)

    require_once ('../mysqli_connect.php');

    $q= "SELECT feed_id, feed_graphic AS graphic FROM feeds_user ORDER By feed_id";
    $r= @mysqli_query ($dbc, $q);

    while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)){


    echo '<table align="center" cellspacing="0" cellpaddin g="5" border="10" width="1100px">
    <tr> .
        <td align="center"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td>
        <td align="center"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td>
        <td align="center"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td>
        <td align="center"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td>
    </tr>'
    ;
    }
    echo
    '</table>';


    ?>
     

  7. I used $r2 as a result object to distinguish it from the $r used in the query above.  In the first part of the post where I posted the entire script you can see that I'm trying to use the script to not only check to see if the form fields are valid and then query the database to see if the record does exist but I also need to make sure the users expiry date is valid.  So I ran a second query and assigned it $q2 and the results $r2.  It's not working for me to say the least!

  8. Hi Hartley:

     

    This is the relevant part that I'm trying to add on to the example script in the book. #12.2 

     

    // Retrieve the expiry date for that userid/password combination:
            
            $q2 = "SELECT expiry_date FROM users WHERE user_id='$u' AND pass='$p'";        
            $r2 = @mysqli_query ($dbc, $q2); // Run the query.
           

    //Check the expiry date against the current date:
        
            if (CURDATE() < $r2); {
            
        // Fetch the record:
                $row = mysqli_fetch_array ($r2, MYSQLI_ASSOC);
        
       // Return true and the record:
                return array(true, $row);
                
            } else { // Mebership Expired!
                $errors[] = 'Your membership has expired. Please click here to renew.';

    }
     

  9. Hey Guys,

     

    Hoping someone can help me with this script.  I'm banging my head against a wall and I suspect that the answer is staring at me in the face.

     

    I'm using the script 12.2 with modifications:

     

    I'm trying to, in addition to checking to see if form fields are filled out and there is a match to also running a query that selects a users expiry date (membership) and then compares is to the current date. If the current date is earlier than the expiry log in should proceed.  If the current date is later than the expiry date then I'm trying to add that message to the error array.

     

    I've pasted the script below.  Thanks in advance! 

     

    Steve

     

    <?php # Script 12.2 - login_functions.inc.php
    // This page defines two functions used by the login/logout process.

    /* This function determines an absolute URL and redirects the user there.
     * The function takes one argument: the page to be redirected to.
     * The argument defaults to index.php.
     */
    function redirect_user ($page = 'index.php') {

        // Start defining the URL...
        // URL is http:// plus the host name plus the current directory:
        $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
        
        // Remove any trailing slashes:
        $url = rtrim($url, '/\\');
        
        // Add the page:
        $url .= '/' . $page;
        
        // Redirect the user:
        header("Location: $url");
        exit(); // Quit the script.

    } // End of redirect_user() function.


    /* This function validates the form data (the email address and password).
     * If both are present, the database is queried.
     * The function requires a database connection.
     * The function returns an array of information, including:
     * - a TRUE/FALSE variable indicating success
     * - an array of either errors or the database result
     */
    function check_login($dbc, $user_id = '', $pass = '') {

        $errors = array(); // Initialize error array.

        // Validate the user id:
        if (empty($user_id)) {
            $errors[] = 'You forgot to enter your user id.';
        } else {
            $u = mysqli_real_escape_string($dbc, trim($user_id));
        }

        // Validate the password:
        if (empty($pass)) {
            $errors[] = 'You forgot to enter your password.';
        } else {
            $p = mysqli_real_escape_string($dbc, trim($pass));
        }

        if (empty($errors)) { // If everything's OK.

            // Retrieve the user_id and first_name for that email/password combination:
            
            $q = "SELECT user_id, first_name FROM users WHERE user_id='$u' AND pass='$p'";        
            $r = @mysqli_query ($dbc, $q); // Run the query.
            
            // Check the result:
            if (mysqli_num_rows($r) == 1) {

                // Fetch the record:
                $row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
        
                // Return true and the record:
                return array(true, $row);
                
            } else { // Not a match!
                $errors[] = 'The userid and password entered do not match those on file.';
            }
            
              // Retrieve the expiry date for that userid/password combination:
            
            $q2 = "SELECT expiry_date FROM users WHERE user_id='$u' AND pass='$p'";        
            $r2 = @mysqli_query ($dbc, $q2); // Run the query.
            
            //Check the expiry date against the current date:
        
            if (CURDATE() < $r2); {
            
                // Fetch the record:
                $row = mysqli_fetch_array ($r2, MYSQLI_ASSOC);
        
                // Return true and the record:
                return array(true, $row);
                
            } else { // Not a match!
                $errors[] = 'Your membership has expired. Please click here to renew.';
            }
            
        }// End of empty($errors) IF.

        // Return false and the errors:
        return array(false, $errors);
        }
     // End of check_login() function.

  10. Heya,

     

    I'm not sure but I would imagine that there is a lot of opportunity.  Check out CraigsList. 

     

    Also of course there is the "virtual office" situation.  So many times I've contracted design and programming out to people I've never met face to face.

     

    Vancouver is real expensive though.  Nanaimo, even Victoria, much less so.  Love it here  It's wonderful having the mountains and the sea.  We had a pod of killler whales in Departure Bay (Nanaimo) twice already this year. If you google it I'm sure you'll see the pictures.  Such an incredible thing to see.

     

    Let me know if you need any info on BC!

     

    Steve

×
×
  • Create New...