pavankat Posted February 18, 2012 Share Posted February 18, 2012 I keep getting this error when I run the following code: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\vitamin-k-tracker\my-meal-planner.php on line 29 <?php include 'top.php'; ?> <?php if (!loggedin()) {//1 if start header('Location: need-to-log-in-mmp.php'); }//1 if end ?> <title>My Meal Planner - Vitamin K Tracker</title> </head> <div id="container"> <?php include 'header.php'; ?> <?php include 'nav.php'; ?> <?php //do sql query to return the foods and nutrients that a person added to their que // // we're doing a left join between the foods and user foods table connected by the id $queryc = "SELECT `foods.id`, `foods.name`, `foods.source`, `users_foods.food_id` FROM `foods` LEFT JOIN users_foods ON foods.id=users_foods.food_id"; $query_runc = mysql_query($queryc); //error on the line below: while ($rowc = mysql_fetch_array($query_runc)){ echo 'ok'; } ?> <div id="content-container"> <div id="content_for_site"> <h2>My Meal Planner</h2> <br /> My Meal Que: <br /> <ul> <form> <li><input type="checkbox" name="meal_one" value="meal_one" /> Meal One</li> How many servings will you have? <input type="text" name="meal_one_servings"><br /><br /> <li><input type="checkbox" name="food_one" value="food_one" /> Food One</li> How many servings will you have? <input type="text" name="meal_one_servings"> </form> </ul> <input type="submit" value="delete" name="delete"><br /> <input type="submit" value="add to calendar" name="add_to_calendar"> <br /><br /> <a href="create-a-meal.php">Create A Meal & add to your Meal Que</a><br /> <a href="find-a-meal.php">Find a Meal or Food to Add to your Meal Que</a> </div> <div id="clear"></div> <?php include 'footer.php'; ?> </div> </div> Link to comment https://forums.phpfreaks.com/topic/257265-expects-parameter-1-to-be-resource-error/ Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 When mysql_query() fails, it returns a boolean FALSE. That indicates your query failed. Use mysql_error to echo the error that was returned from MySQL. Link to comment https://forums.phpfreaks.com/topic/257265-expects-parameter-1-to-be-resource-error/#findComment-1318691 Share on other sites More sharing options...
pavankat Posted February 18, 2012 Author Share Posted February 18, 2012 Thanks dude. Apparently it said that foods.id didn't exist - but it did. So I re wrote the query like this: $queryc = "SELECT `name`, `source`, `food_id` FROM `foods` LEFT JOIN users_foods ON foods.id=users_foods.food_id"; and it worked. But I used foods.id at the bottom. Not sure why that happened. Link to comment https://forums.phpfreaks.com/topic/257265-expects-parameter-1-to-be-resource-error/#findComment-1318711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.