Hi I am trying a php code to insert record into a table.
<?php
$server = "localhost";
$user = "root";
$pwd = "";
$db_con = mysql_connect($server,$user,$pwd);
$select_db = mysql_select_db("test_database",$db_con);
$txnid = date ("ydmHis") . mt_rand(1000, 9999);
$custnumber = "4316010100000001";
$cust_mo_num = "7875432990";
$bc_id = "LTH001";
$timestamp = "12:12:12:12:12:12";
$amounta = "500";
$txnupdate = "INSERT INTO cust_txn (txnid,cust_num,cust_mo_num,bc_username,txn_time,txn_amount,txn_type,txn_status) VALUES ('$txnid','$custnumber','$cust_mo_num','$bc_id','$timestamp','$amounta','WTH','SUCC')";
$result = mysql_query($txnupdate);
mysql_close($db_con);
echo $result;
?>
When I run this page and refresh it, the record is inserted only once. (The txnid is primary key and I do change it every time.) I have no way to know where am I going wrong.
Your code is working fine. I just capitalize table name since i’m using ubunthu box. (Your create table statement provided with CUST_TXN table name)
SOURCE
RESULTS
Also you can use current_timestamp for your txn_time column
MYSQL DDL
SOURCE
RESULTS