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
| SitePoint Sponsor |
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



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>
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
%>



LOL... didn't even realize I was in the ASP board... that's what I get for using "new posts"![]()



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 %>





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.



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