adamriley Posted March 13, 2010 Share Posted March 13, 2010 Hi could any one say why this is not working ------------------------------------------------------------------------------------------------------- <?php $username = "adam"; $password = "adamriley1996"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("examples",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT id, model,year FROM cars"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "ID:".$row{'id'}." Name:".$row{'model'}."Year: ". //display the results $row{'year'}."<br>"; } //close the connection mysql_close($dbhandle); ?> ---------------------------------------------------------------------------------- error log -------------------- Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/195125-mysql-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2010 Share Posted March 13, 2010 http://www.phpfreaks.com/forums/index.php/topic,290968.msg1377912.html#msg1377912 Quote Link to comment https://forums.phpfreaks.com/topic/195125-mysql-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1025650 Share on other sites More sharing options...
adamriley Posted March 13, 2010 Author Share Posted March 13, 2010 ok fixed that one but what about this <?php $username = "adam"; $password = "adamriley1996"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("examples",$dbhandle) or die("Could not select examples"); $a1 = <<<my INSERT INTO cars VALUES(1,'Mercedes','2000'); INSERT INTO cars VALUES(2,'BMW','2004'); INSERT INTO cars VALUES(3,'Audi','2001'); my; mysql_query("$a1"); // execute the SQL query and return records $result1 = mysql_query("SELECT id, model,year FROM cars"); // fetch that data from the database while ($row = mysql_fetch_array($result1)) { echo "ID:".$row{'id'}." Name:".$row{'model'}."Year: ". //display the results $row{'year'}."<br>"; } // close the connection echo mysql_error(); mysql_close($dbhandle); ?> ------------ error log || nothing --------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/195125-mysql-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1025652 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2010 Share Posted March 13, 2010 You cannot execute multiple queries separated by semi-colons using the mysql_query() function. Too many 'programmers' were not validating external data to prevent sql injection so the msyql_query() function does not support multiple sql statements. You either need to execute each query separately or you need to form a multi-value INSERT using a list of comma separated values. INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); Quote Link to comment https://forums.phpfreaks.com/topic/195125-mysql-warning-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1025662 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.