Help me..

i dont know whats prob in this very simple code…i’m getting error like this…

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\form2.php on line 48

<?php $conn=mysql_connect("localhost","root",""); if(!$conn) { die("Error").mysql_error(); } $db=mysql_query("CREATE DATABASE IF NOT EXISTS database2",$conn); //mysql_query($db,$conn); if(!$db) { die("db not created").mysql_error(); } else{echo "db created";} mysql_query(mysql_select_db("database2",$conn)); mysql_query("CREATE TABLE IF NOT EXISTS products( product_id int NOT NULL, prod_name varchar(20), type varchar(20), PRIMARY KEY(product_id))") or die(mysql_error()); mysql_query("CREATE TABLE IF NOT EXISTS orders( order_id int(3), user_name varchar(20), count int(2), product_id int(2), PRIMARY KEY(order_id), FOREIGN KEY(product_id) REFERENCES products(product_id))") or die(mysql_error()); $result=mysql_query("SELECT products.prod_name,orders.user_name from producs INNER JOIN orders on products.product_id=orders.product_id"); while($row = mysql_fetch_array($result)){ echo $row['prod_name']. " - ". $row['user_name']; echo "
"; } ?>

i’m using innodb tables… i have added values of both tables via phpmyadmin after executing this program…but still am getting error…

Hi there,

It’s because $result from your mysql_query is returning false rather than the resource containing the data select from your mysql query. Your query is mostly likely erroring because you have written “from producs” rather than “from products”.

Thanks a lot… works fine now… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service