Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:05:11+00:00 2026-06-01T16:05:11+00:00

Hi I am trying a php code to insert record into a table. <?php

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:05:12+00:00Added an answer on June 1, 2026 at 4:05 pm

    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

    <?php
    $user = "root";
    $pwd = "root123";
    $db_con = mysql_connect($server,$user,$pwd);
    $select_db = mysql_select_db("ci",$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')";
    echo $txnupdate;
    $result = mysql_query($txnupdate);
    mysql_close($db_con);
    echo $result;
    ?>
    

    RESULTS

    > select * from CUST_TXN;
    +------------------+------------------+-------------+-------------+-------------------+------------+----------+------------+
    | txnid            | cust_num         | cust_mo_num | bc_username | txn_time          | txn_amount | txn_type | txn_status |
    +------------------+------------------+-------------+-------------+-------------------+------------+----------+------------+
    | 1209042028162311 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    | 1209042028177407 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    | 1209042028194204 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    | 1209042028342444 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    | 1209042028358383 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    | 1209042028362068 | 4316010100000001 | 7875432990  | LTH001      | 12:12:12:12:12:12 | 500        | WTH      | SUCC       |
    +------------------+------------------+-------------+-------------+-------------------+------------+----------+------------+
    

    Also you can use current_timestamp for your txn_time column

    MYSQL DDL

    CREATE TABLE CUST_TXN_2 ( txnid char(16), PRIMARY KEY(txnid), cust_num char(16), cust_mo_num char(10), bc_username char(6), txn_time timestamp DEFAULT CURRENT_TIMESTAMP, txn_amount varchar(10), txn_type varchar(5), txn_status varchar(10) );
    

    SOURCE

    <?php
    $user = "root";
    $pwd = "root123";
    $db_con = mysql_connect($server,$user,$pwd);
    $select_db = mysql_select_db("ci",$db_con);
    $txnid = date ("ydmHis") . mt_rand(1000, 9999);
    $custnumber = "4316010100000001";
    $cust_mo_num = "7875432990";
    $bc_id = "LTH001";
    $amounta = "500";
    $txnupdate = "INSERT INTO CUST_TXN_2 (txnid,cust_num,cust_mo_num,bc_username,txn_amount,txn_type,txn_status) VALUES ('$txnid','$custnumber','$cust_mo_num','$bc_id','$amounta','WTH','SUCC')";
    echo $txnupdate;
    $result = mysql_query($txnupdate);
    mysql_close($db_con);
    echo $result;
    ?>
    

    RESULTS

    > select * from CUST_TXN_2;
    +------------------+------------------+-------------+-------------+---------------------+------------+----------+------------+
    | txnid            | cust_num         | cust_mo_num | bc_username | txn_time            | txn_amount | txn_type | txn_status |
    +------------------+------------------+-------------+-------------+---------------------+------------+----------+------------+
    | 1209042055524683 | 4316010100000001 | 7875432990  | LTH001      | 2012-04-09 20:55:52 | 500        | WTH      | SUCC       |
    | 1209042055563581 | 4316010100000001 | 7875432990  | LTH001      | 2012-04-09 20:55:56 | 500        | WTH      | SUCC       |
    | 1209042055564435 | 4316010100000001 | 7875432990  | LTH001      | 2012-04-09 20:55:56 | 500        | WTH      | SUCC       |
    | 1209042055579931 | 4316010100000001 | 7875432990  | LTH001      | 2012-04-09 20:55:57 | 500        | WTH      | SUCC       |
    +------------------+------------------+-------------+-------------+---------------------+------------+----------+------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert things by PHP code into the course sections every
I am trying to insert php variables into javascript. Here is the broken code:
I am trying to insert a future date into a MySQL table from PHP.
I'm trying to insert registration data into a database but my php code isn't
I am trying to create a table within PHP code in order to open
I am going nuts trying to use PHP to get and insert values into
I'm trying to insert THE PHP CODE between the <div id=container> THE PHP CODE
i am trying to upload a image to server from iPhone application PHP code
I'm trying to insert a php code for a post-rating on wordpress. It used
I am currently trying to insert data into a table called customer_quote , this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.