Jump to content
Larry Ullman's Book Forums

selliottsxm

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by selliottsxm

  1. Got it: require_once ('../mysqli_connect.php'); $movie_id = $_GET['movie_id']; $q = mysqli_query($dbc,"SELECT * FROM movies WHERE movie_id = $movie_id"); $r = mysqli_fetch_array($q); Thanks for making me figure it out
  2. 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
  3. 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)
  4. Correction: The query is actually: $q = "SELECT * FROM movies WHERE movie_id = $movie_id";
  5. 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?
  6. Scratching my head too. Left outer join didn't work. All spelling is correct and table have all the fields. Going to leave it for a day and look at it again. Thanks again Antonio, very nice of you to help
  7. Hi Antonio, Thanks very much for the help. Didn't work though. Taking out the genre part and replacing it with actor names gave me the same result. Left outer join didn't make a difference either. I think that I have the relationships correct. Back to the drawing board! Steve
  8. 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?
  9. I started fooling around with the incrementing variable $i It's getting there. Now I have 8 images in each row (each one appearing twice)
  10. I tried that one already. All it does is give me the same graphic four times in one row
  11. 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>'; ?>
  12. I figured it out. My file permissions were not set correctly and therefore only one image (which for some reason was set right) was displaying!
  13. 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>'; ?>
  14. Yes I think so. What I've done is to modify the SQL statement including expiry_date in the SELECT and expiry_date > NOW() in the WHERE clause. It returns the error array but I can't figure out how to add the error "You membership has expired" to the array.
  15. 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!
  16. 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.'; }
  17. 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.
  18. HI, In chapter 12 we edited the header.html script and included for link 5 a php conditional. I thought that in order to process php the file extension had to be .php? However the script works perfectly. I must be wrong about the necessity of the .php file extension? Thanks, Steve
  19. Hey Guys, Thanks for the comments I really appreciate it. I'll let you know how we handled it when we get around the installing the new site. Currently we are passing values from a .cfm script to a php script. I think it was handled by editing the Apache config file by way of a file handler statement. Steve
  20. I'm rewriting a site that uses a join script with the extension of .cfm The url has variables that the script uses in adding a user after a succsessful purchase. Instead of trying a redirect to a php page I thought it might be easier for the server to treat the cfm extension as php.
  21. Hello Can someone verify for me that it's possible to edit the .htaccess file making it possible for a page with the extension of .cfm to be treated as a php file? For example: AddType application/x-httpd-php .php .htm .html .cfm Will that work ok? Thanks in advance, Steve
  22. 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
  23. Yes it does. It had just occured to me and I was logging back into to delete the message. Thanks for all your help! The last time that I designed a website interacting with a database was in '97 using Cold Fusion
×
×
  • Create New...