Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Insert Problem

  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post

    Insert Problem

    Dear Sir,

    I have following codes to save record in MySql.

    PHP Code:
    <?php
        
    include("connect.php");
        
    $insert_query "INSERT INTO ghee (sno,pack,weight) VALUES (18,'kk',80)";
        
    $insertion_result mysql_query($insert_query);
        
    //check whether the data insertion was successful
        
    if(!$insertion_result)
        {
             die(
    "Sorry! Something went wrong.</p>");    
        }
        else
        {
            echo 
    "<p>Record saved successfully.</p>";    
        }
        
    mysql_close();
    ?>
    These codes work fine, no error. But I need some modification as

    In above code these values are going to save
    Code:
    VALUES (18,'kk',80)";
    If I press submit button then values are written in dbf.
    But if I press submit button MORE THAN ONE TIME then everytime it says:

    PHP Code:
    echo "<p>Record saved successfully.</p>"

    Before sending data to table it must check whether current SNO=18 already exist or not. If already exist then it must say:

    PHP Code:
    die "<p>Current SNO already exists .</p>"
    Please help

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Make the field sno as an auto-increment (primary key) one. The db will take care of it and you don't have to insert anything to it.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •