-5

I already done this. and what can i found out is, everything that i put inside the form doesnt insert into the table in phpmyadmin. hope someone can help me. thankyou :)

$icode=$_POST["icode"];
$iqty=$_POST["iqty"];
$curr_date = date("Y-m-d");
$iexp=$_POST["iexp"];
$ibankin=$_POST["ibankin"];

switch($icode)
{
    case "1" : $price = 16.00; $iitem="Ayam"; break;
    case "2" : $price = 7.00; $iitem="Daging"; break;
    case "3" : $price = 8.00; $iitem="Ikan"; break;
    default : $price = 0.00; $item="Invalid Code"; break;
}

$sales = $price * $iqty;
echo "<br>$curr_date";
echo "<br>$iitem";
echo "<br>$price";
echo "<br>$sales";
echo "<br>$iexp";
echo "<br>$ibankin";

mysql_query("insert into new (D_date, D_sales, D_expenses, D_bankin, D_item)
        values ('$curr_date',$sales,$iexp,$ibankin,$iitem)");
Jocelyn
  • 11,209
  • 10
  • 43
  • 60
  • 2
    Where is your `mysql_connect()` statement? Also I suggest using PDO. I suggest reading [this](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access) article. – aborted Feb 22 '13 at 01:33
  • You need quotes around each of the string values you are inserting. Also, you should be using [mysqli](http://php.net/manual/en/book.mysqli.php) instead of mysql. – Will Feb 22 '13 at 01:36
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit Feb 22 '13 at 01:39

1 Answers1

1

You need to put single quotes around string values you are trying to insert.

Try this:

    mysql_query("insert into new (D_date, D_sales, D_expenses, D_bankin, D_item)
    values ('$curr_date','$sales','$iexp','$ibankin','$iitem')");

This will work for you, however have a look at escaping all values you take from users before putting them in the database.

ChrisK
  • 1,392
  • 10
  • 12