danalvess Posted June 1, 2013 Share Posted June 1, 2013 Hello, i need help!!! <?php $query = mysql_query("SELECT 'id', 'name', 'url' FROM videos"); while($run = mysql_fetch_array($query)){ $video_id = $run['id']; $video_name = $run['name']; $video_url = $run['url']; ?> Error:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/ Share on other sites More sharing options...
boompa Posted June 1, 2013 Share Posted June 1, 2013 Your query failed because you're using single quote. If a query fails, then $query will be FALSE, but mysql_fetch_array() expects a resource (hence the error). So: 1. Don't use single quotes, use backticks. 2. Check that the $query variable is not FALSE before using it. <?php $query = mysql_query("SELECT `id`, `name`, `url` FROM videos"); if (!$query) { die('Query failed: ' . mysql_error()); } while($run = mysql_fetch_array($query)){ $video_id = $run['id']; $video_name = $run['name']; $video_url = $run['url']; } ?> Also, you should look into using mysqli_* or PDO for MySQL access in PHP; the mysql_* extension has been deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433596 Share on other sites More sharing options...
danalvess Posted June 1, 2013 Author Share Posted June 1, 2013 Thank, more a new error ??? Query failed: No database selected Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433597 Share on other sites More sharing options...
Jessica Posted June 1, 2013 Share Posted June 1, 2013 Well. That pretty much says what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433599 Share on other sites More sharing options...
Jessica Posted June 1, 2013 Share Posted June 1, 2013 Your query failed because you're using single quote. No, it didn't. That's a perfectly valid query. It probably won't produce what OP wants, but it's not going to fail. Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433600 Share on other sites More sharing options...
danalvess Posted June 1, 2013 Author Share Posted June 1, 2013 ??? Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433601 Share on other sites More sharing options...
Jessica Posted June 2, 2013 Share Posted June 2, 2013 ???What is the problem? Read the error. Resolve the issue. Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433603 Share on other sites More sharing options...
boompa Posted June 2, 2013 Share Posted June 2, 2013 No, it didn't. That's a perfectly valid query. It probably won't produce what OP wants, but it's not going to fail. Well you learn something new every day. I use PDO and prepared statements, a framework-based ORM through PHP, or use the command line MySQL client and I've never seen or used single quotes in a query before and made a bad assumption. Thanks for straightening me out. Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433644 Share on other sites More sharing options...
danalvess Posted June 2, 2013 Author Share Posted June 2, 2013 Ok, thanks Quote Link to comment https://forums.phpfreaks.com/topic/278675-error-with-php-and-mysql/#findComment-1433698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.