selliottsxm Posted May 27, 2014 Share Posted May 27, 2014 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? Link to comment Share on other sites More sharing options...
selliottsxm Posted May 27, 2014 Author Share Posted May 27, 2014 Correction: The query is actually: $q = "SELECT * FROM movies WHERE movie_id = $movie_id"; Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2014 Share Posted May 27, 2014 Did that correction solve your problem, or are you still getting an error? What kind of error are you getting? Link to comment Share on other sites More sharing options...
selliottsxm Posted May 27, 2014 Author Share Posted May 27, 2014 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) Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2014 Share Posted May 27, 2014 It's because you haven't actually executed the query yet with mysqli_query. Use that function to execute the query and store the result in a variable. From there, make the first argument of mysqli_fetch_array the returned results object, not the DB connection. Link to comment Share on other sites More sharing options...
selliottsxm Posted May 27, 2014 Author Share Posted May 27, 2014 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 Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2014 Share Posted May 27, 2014 Please check Larry's books and/or an online resource for the answer.Basically, the mysqli_query function requires two arguments. Link to comment Share on other sites More sharing options...
selliottsxm Posted May 27, 2014 Author Share Posted May 27, 2014 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 Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2014 Share Posted May 27, 2014 Sure thing. Link to comment Share on other sites More sharing options...
Recommended Posts