SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Multi-function Button

    Hi All
    I'm trying to get a button to get one click of abutton to both add a new record in a sql database and edit an existing one. I'm pretty new to this so be gentle and all and any ideas are appreciated!
    Thanks in advance hopefully

  2. #2
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this should get you started...
    PHP Code:
    <?php

    if ($_POST["button_clicked"] == 1) {
        
    $cn mysql_connect("localhost""username""password");
        
    mysql_select_db("catalog"$cn);
        
    mysql_query("INSERT INTO table1 (id, name) VALUES ('{$id}', '{$name}')"$cn);
        
    mysql_query("UPDATE table2 SET id = '{$id}', name = '{$name}')"$cn);
    }
    ?>
    <form action="<?=$PHP_SELF?>" method="post">
        <input type="hidden" name="button_clicked" value="1" />
        <button type="submit">Do it!!!!</button>
    </form>

  3. #3
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just change the above code to ASP
    <%

    if len(request ("button_clicked") > 0 than
    '# Connect to database
    '# Record Insert Query
    '# Record Update Query
    end if

    %>

  4. #4
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL... didn't even realize I was in the ASP board... that's what I get for using "new posts"

  5. #5
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code ASP:
    <%
    If Len(Request.getParameter("button_clicked") > 0 Then
     
        'Connect to database
        Dim oCn
        Set oCn = Server.CreateObject("ADODB.Connection")
        oCn.Open "Connection String" 
     
        'Record Insert Query
        oCn.Execute("INSERT INTO...")
     
        'Record Update Query
        oCn.Execute("UPDATE...")
     
    End If
    %>

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If Len(Request.getParameter("button_clicked") > 0 Then

    ???

    If the form method is POST then use Request.Form. Use Request.Querystring if the method is GET (or is not defined) - i.e. if you see the parameter=value details in the URL.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    If Len(Request.getParameter("button_clicked") > 0 Then

    ???

    If the form method is POST then use Request.Form. Use Request.Querystring if the method is GET (or is not defined) - i.e. if you see the parameter=value details in the URL.
    Crap, you're totally right... Request.getParameter is Java (HTTPServletRequest), not ASP... it's been about 7 years, so forgive me!!!

  8. #8
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replys, I'm not having much joy though. I'm a beginner and playing with someone elses code, I've attached what I'm playing with any help would be really really appreciated.

    Thanks
    Attached Files Attached Files


Bookmarks

Posting Permissions

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