Hi Guyz
I am inserting into a mysql database usiing ASP, I keep getting an error but for the life of me can not see the problem, thought a fresh set of yes might help. If you can assist that would be very helpful. I suspect its something stupid that I am just not seeing, so no rude remarks :)
Here is my code:
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
<%
'
' Database connection code.
'
' Use rsResult for returning queries.
'
Dim adoCon_news 'Holds the Database Connection Object
Dim rsResult_news 'Holds the recordset for the records in the database
Dim strSQL_news 'Holds the SQL query to query the database
'Create an ADO connection object.
Set adoCon_news = Server.CreateObject("ADODB
.Connectio
n")
' This is the live MySQL database.
adoCon_news.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; UID=***; PWD=***; DATABASE=***"
' Create the Recordset.
Set rsResult_news = Server.CreateObject( "ADODB.Recordset" )
%>
<!-- #include file="../news_toolbox/incl
udes/dbcon
n.inc.asp"
--> 'included above above
<%
strsql = "insert into news "
strsql = strsql + "("
strsql = strsql + "client_id, "
strsql = strsql + "title, "
strsql = strsql + "article, "
strsql = strsql + "date_added "
strsql = strsql + ")"
strsql = strsql + "values "
strsql = strsql + "("
strsql = strsql + "'" & request.form("client_id") & "', "
strsql = strsql + "'" & request.form("article_titl
e") & "', "
strsql = strsql + "'" & request.form("article_body
") & "', "
strsql = strsql + "now() "
strsql = strsql + ")"
rsResult.Open strsql, adocon_news
response.write "Article Successfully Saved<br>"
response.write "<a href=press_center_article_
admin.asp>
Return To Press Center Admin</a>"
%>
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
****
The page that submits the data is here
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
****
<!-- #include file="includes/dbconn.inc.
asp" -->
<!-- #include file="authorisation/client
_id.auth.a
sp" -->
<!-- #include file="includes/templates_a
rticle_add
.inc.asp" --> 'this is below
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
*
<script>
function verify()
{
var errs = '';
document.article_add.artic
le_title.v
alue = clean(document.article_add
.article_t
itle.value
);
document.article_add.artic
le_body.va
lue = clean(document.article_add
.article_b
ody.value)
;
if (document.article_add.arti
cle_title.
value.leng
th == 0)
{
errs += 'A title must be provided\n';
}
if (document.article_add.arti
cle_body.v
alue.lengt
h == 0)
{
errs += 'Body text must be provided\n';
}
if (errs.length != 0)
{
alert(errs);
}
else
{
document.article_add.actio
n = 'article_save.asp';
document.article_add.submi
t();
}
}
function clean(txt)
{
while (txt.indexOf("'") != -1)
{
txt = txt.replace("'","");
}
return txt;
}
</script>
<form name=article_add action=javascript:verify()
method=post>
<table cellpadding=0 cellspacing=0 align=left border=0>
<tr>
<td width="125" valign="top">
Article Owner
</td>
<td>
<%
if Authorised_Client_Id = 0 then
strsql_news = "select client_id, company_name from clients order by company_name"
rsResult_news.open strsql_news, adocon_news
if not(rsResult_news.EOF and rsResult_news.BOF) then
response.write "<select name=client_id>"
while not rsResult_news.EOF
Response.Write "<option value=" & rsResult_news("client_id")
& ">" & rsResult_news("company_nam
e") & "</option>"
rsResult_news.movenext
wend
response.write "</select>"
end if
else
strsql_news = "select client_id, company_name from clients where client_id = '" & Authorised_Client_Id & "'"
rsResult_news.open strsql_news, adocon_news
if not(rsResult_news.EOF and rsResult_news.BOF) then
response.write rsResult_news("company_nam
e") & "<input type=hidden name=client_id value=" & rsResult_news("client_id")
& ">"
else
'response.redirect "Smeg Off!.asp"
end if
end if
%>
</td>
</tr>
<tr>
<td valign="top">
Article Title
</td>
<td>
<input type=text name=article_title id=article_title value="" alt="Article Title" maxlength=255 size="67">
</td>
</tr>
<tr>
<td valign="top">
Article Body
</td>
<td>
<textarea rows=10 cols=50 name=article_body id=article_body></textarea
>
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=submit name=submit>
</td>
</tr>
<tr>
<td colspan=2>
<a href=../../news toolbox/includes/Press_cen
ter_articl
e_admin.as
p>Return To Press Center Administration</a>
</td>
<tr>
</table>
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
*******
As I say prob something stupid that I have missed.
Kind regards
Marcus Anderson Hitchen
Start Free Trial