Hi, If you're learning try PDO instead of mysql_* extension, mysql_* extension was already deprecated
http://php.net/manual/en/book.pdo.php
Using PDO, it is much easy to insert row on your database
// Create instance of PDO so you can perform your query (e.g. insert rows, fetch datas, etc.)
try
{
$dbh = new PDO('mysql:host=yourhostname;dbname=yourdbname;charset=utf8', 'yourdbusername', 'yourdbpassword');
}
catch (PDOException $e)
{
// Catch errors, such as invalid username/password/dbname/hostname/etc...
// you can do what you want here with the errors, I just use die for simplicity
die('Cannot connect to database: ' . $e->getMessage());
}
// If successfull, we can now perform query
// Names starting with ":" are just placeholders
// Using the query method, PDO will sanitize input before it store the datas in the database to prevent SQL injection
$query = 'INSERT INTO ho_add_stock_proforma (supplier, inv_no, day, month, year, product_name, descrpt, qty, cost, hawker, wholesale, retail, total)
VALUES (:supplier, :inv_no, :day, :month, :year, :product_name, :descrpt, :qty, :cost, :hawker, :wholesale, :retail, :total)';
// Perform the query inside the try & catch so we can handle if there's an error on our code
try
{
$stmt = $dbh->prepare($query);
// We can now bind the value in our query
$stmt->execute(array(
':supplier' => $_POST['supplier'],
':inv_no' => $_POST['inv_no'],
':day' => $_POST['day'],
// insert your other $_POST data...
));
}
catch (PDOException $e)
{
// Again, we need to catch if there's an error on our query
die('Cannot perform the query: ' . $e->getMessage());
}
// If successful, perform your other code...