Nur
asked on
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[a maun]');") ;
}
?>
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[a maun]',$_P OST[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
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[a
}
?>
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[a
}
?>
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
mysql_query("INSERT INTO `teksi`.`resit` (`no_kupon` ,`tarikh` ,'amaun',`kasyer`) VALUES ( '$_POST[no_kupon]', '$_POST[tarikh]','$_POST[awhat error you encountered here?maun]',$_P OST[kasyer ]');");
ok, you may try this:
the single quote for 'amaun' is invalid. ' should be placed as `
mysql_query("INSERT INTO `teksi`.`resit` (`no_kupon` ,`tarikh` ,`amaun`,`kasyer`) VALUES ( '$_POST[no_kupon]', '$_POST[tarikh]','$_POST[amaun]',$_POST[kasyer]');");
the single quote for 'amaun' is invalid. ' should be placed as `
ASKER
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.
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.
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?
ASKER
I have tried a sample provided in comment: ID: 42038757 but the the data still failed to save into database
$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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
Please check if below code works.
Open in new window