SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Multi-function Button
-
Mar 19, 2011, 13:06 #1
- Join Date
- Mar 2011
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Mar 19, 2011, 13:15 #2
- Join Date
- Apr 2004
- Location
- Miami, FL, USA
- Posts
- 448
- 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>
-
Mar 20, 2011, 08:53 #3
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
%>
-
Mar 20, 2011, 08:59 #4
- Join Date
- Apr 2004
- Location
- Miami, FL, USA
- Posts
- 448
- 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"
-
Mar 20, 2011, 09:03 #5
- Join Date
- Apr 2004
- Location
- Miami, FL, USA
- Posts
- 448
- 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 %>
-
Mar 20, 2011, 16:36 #6
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- 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.
-
Mar 20, 2011, 16:46 #7
- Join Date
- Apr 2004
- Location
- Miami, FL, USA
- Posts
- 448
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 28, 2011, 08:06 #8
- 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
Bookmarks