php - Table 'stock1.products1' doesn't exist -


i'm creating database , table. here's code db , table creation :

<?php //error_reporting(e_all); //connect mysql $db = mysql_connect('127.0.0.1', 'root', '') or die ('unable connect.check connection parameters'); //create main database if doesn't exists $query = 'create database stock1'; mysql_query($query, $db) or die (mysql_error($db)); //make sure our created db active 1 mysql_select_db('stock1', $db) or die (mysql_error($db));  //create products table $query = 'create table products1(          product_id     integer unsigned    not null    auto_increment,          product_name   varchar(40)         not null,          product_stock  smallint unsigned   not null default 0,           primary key(product_id)          )';           echo "success";           ?> 

after this, create file accepts 2 inputs , transmits data php file. here's html:

<html> <head> <title>inventory - backend</title> </head> <body>  <form action="addproducts.php" method="post"> <table> <tr> <td>product name : </td> <td><input type="text" name="pname"/></td> </tr> <tr> <td>product quantity : </td> <td><input type="text" name="productq"/></td> </tr> <tr> <td></td> </tr> <tr> <td><input type="submit" name="add product"/></td> </tr> </table> </form> </body> </html> 

here's backed:

<?php $db = mysql_connect('127.0.0.1', 'root', '') or die ('unable connect.check connection parameters'); mysql_select_db('stock1', $db) or die (mysql_error($db));  $productname=$_post['pname']; $productquantity=$_post['productq'];  $query = 'insert products1           (product_id, product_name, product_stock)           values           (null, "' . $productname . '", ' . $productquantity . ')';            mysql_query($query, $db) or die (mysql_error($db));           echo "product added";           ?> 

but, when try run script, error:

table 'stock1.products1' doesn't exist 

can tell me why error appears? , how can fix it?

you forgot execute query creates table:

$query = 'create table products1(          product_id     integer unsigned    not null    auto_increment,          product_name   varchar(40)         not null,          product_stock  smallint unsigned   not null default 0,           primary key(product_id)          )';  mysql_query($query);  echo "success"; 

the line mysql_query($query); missing in code.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -