Inserting data into database

Hi experts...

I have a problem in inserting data  which i have four attributes(no_kupon, tarikh,amaun,kasyer) to be insert into a table (resit)

The problem is only 3 attributes can be inserted into a table:
<?php
 if(isset($_POST['simpan'])){
  mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun') VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]');");
  }
 ?>

when i use this sql to insert 4 attributes the data failed to be sent into database
<?php
 if(isset($_POST['simpan'])){
  mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun',`kasyer`) VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]',$_POST[kasyer]');");
  }
 ?>

here is my full coding: https://jsfiddle.net/Lp67q7p0/

Please someone here help me...I only have a day to settle this problem before submission.Thank you
NurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peos JohnPHPCommented:
You can you "+ dot(.) symbol to combine the variables into string.  Can you post what is the error exactly you are getting?

Please check if below code works.

  if(isset($_POST['simpan'])){
	  
	  print_r($_POST);
	  
  mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun',`kasyer`) VALUES ( '".$_POST[no_kupon]."', '".$_POST[tarikh]."','".$_POST[amaun]."','".$_POST[kasyer]."');"); 
  }
 ?>

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
 mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun',`kasyer`) VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]',$_POST[kasyer]');");
what error you encountered here?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, you may try this:

mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,`amaun`,`kasyer`) VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]',$_POST[kasyer]');"); 

Open in new window


the single quote for 'amaun' is invalid. ' should be placed as `
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

NurAuthor Commented:
actually there is no error display for my coding but when i listed 3 attribute in my sql (no_kupon, tarikh,amaun).It was successfully added into database.

But, when I am trying to listed 4 attribute in my sql(no_kupon, tarikh,amaun,kasyer). It was unsuccessfully added into database.

I don't know what i am supposed to do since I had to listed only 3 attribute in sql to ensure the data inserted into database.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
But, when I am trying to listed 4 attribute in my sql(no_kupon, tarikh,amaun,kasyer). It was unsuccessfully added into database.
as already explained and provided a sample in comment: ID: 42038757. Have you tried that?

if it's not working, tell us what error you getting here?
0
NurAuthor Commented:
I have tried a sample provided in comment: ID: 42038757 but the the data still failed to save into database
0
Peos JohnPHPCommented:
$query  = "INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun',`kasyer`) VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]',$_POST[kasyer]');"

echo $query; // THIS WILL PRINT THE QUERY

Open in new window



Once you see the query on browser, you can try running directly in mysql(if you are using phpmyadmin, you can run the query manually by pasting the sql statement into run).  

Also check if table has the  relevant column name.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ooops, try this instead:

mysql_query("INSERT INTO  `teksi`.`resit` (`no_kupon` ,`tarikh` ,`amaun`,`kasyer`) VALUES ( '$_POST[no_kupon]',  '$_POST[tarikh]','$_POST[amaun]', '$_POST[kasyer]');"); 

Open in new window


your statement is without the opening single quote for its value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NurAuthor Commented:
ohh yess!! finally it can be save. I used a sample provided in comment ID: 42038867. thank you a lot to all of you for helping me
0
Ray PaseurCommented:
First things first...  NEVER put external variables ($_POST) into a query string.  You must escape the variables or your script will get hacked and your database will get destroyed.

Next, there are examples in these comments that misuse quotation marks in ways that might cause the scripts to fail at run time.  Here is what you need to know about quotes.
https://www.experts-exchange.com/articles/12241/Quotation-Marks-in-PHP.html

Now on to the longer-term issues that call for refactoring...  You can't use MySQL any more.  PHP has removed support for the MySQL extension, and you will have to change your scripts to stop using MySQL.  There are two other extensions that will let you continue to use your database.  Here is the explanation with examples of how to keep your scripts running in the future.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.