Trucsweb.com

Forum de discussion

 Forum « Programmation ASP » (archives)

Re: pb de saisie dans un formulaire

Envoyé: 27 janvier 2005, 11h48 par cmi11


J'ai regardé ce que tu m'as dit, mais je en trouve rien.

J'ai 2 fichiers similaires de saisie, l'un fonctionne l'autre non.

Ci-joint les codes :

1 - Celui qui fonctionne :
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/test.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection = MM_test_STRING
MM_editTable = "tblInfo"
MM_editRedirectUrl = "http://dsf110.eole.dgi";
MM_fieldsStr = "dateinfo|value|infos|value"
MM_columnsStr = "dateinfo|',none,NULL|infos|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<html>
<head>
<title>DSF110 - Saisie info du jour</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../styles1.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../js/twvalide.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var varValid = "dateinfo,infos";

// LANGAGE PAR DÉFAUT
// Entrer "fr" pour français, rien pour englais.
var nlang = "fr"
// ********************************************
// -->
</script>
</head>

<body>

<p> </p>
<p> </p>
<p align="center" class="actuUne">Formulaire de saisie des infos du jour</p>


<form method="post" action="<%=MM_editAction%>" name="form1">
<table width="698" align="center">
<tr valign="baseline">
<td width="94" align="right" nowrap class="homeRubTitre">Date de l'info</td>
<td align="right" valign="baseline"> <div align="right">
<input type="text" name="dateinfo" value="" onBlur="twValide_date(this,1950,2020,'jj/mm/aaaa')" align="right" size="20">
</div></td>
<td> </td>
</tr>
<tr valign="baseline">
<td height="105" valign="top" nowrap class="homeRubTitre">Contenu de l'info</td>
<td colspan="2"> <textarea name="infos" cols="80" rows="10"></textarea> </td>
</tr>
<tr valign="baseline">
<td height="17" align="right" nowrap> </td>
<td colspan="2"> </td>
</tr>
<tr valign="baseline">
<td height="25" align="right" nowrap> </td>
<td width="104">  </td>
<td width="484"><input name="submit" type="submit" class="homeRubTitre" value="Insérer l'enregistrement"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>

2 Celui qui ne fonctionne pas
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/epice.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection = MM_epice_STRING
MM_editTable = "tblAgent"
MM_editRedirectUrl = ""
MM_fieldsStr = "grade|value|nomagent|value|numdgi|value|password|value|patroni|value|prenom|value"
MM_columnsStr = "grade|',none,''|nomagent|',none,''|numdgi|none,none,NULL|password|',none,''|patroni|',none,''|prenom|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p> </p>
<p> </p>
<p> </p>




<p> </p>




<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Grade:</td>
<td> <input type="text" name="grade" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nomagent:</td>
<td> <input type="text" name="nomagent" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Numdgi:</td>
<td> <input type="text" name="numdgi" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Password:</td>
<td> <input type="text" name="password" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Patroni:</td>
<td> <input type="text" name="patroni" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Prenom:</td>
<td> <input type="text" name="prenom" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td> <input type="submit" value="Insérer l'enregistrement"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>

Ci-joint les connexions

1 test.asp
<%
' FileName="Connection_ado_conn_string.htm"
Dim MM_test_STRING
MM_test_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/html/infojour/infojour.mdb")
%>

2 epice.asp
<%
' FileName="Connection_ado_conn_string.htm"

Dim MM_epice_STRING
MM_epice_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/html/cmi/epice.mdb")
%>

J'ai toujours une erreur "insert into"
Ma base access contient juste une table, j'ai fait attention aux mots réservés et mes noms de champs font au plus 8 caractères.
Je suis dans la merde...


Réponses

 sp spRe: pb de saisie dans un formulaire Oznog27/1/2005
 sp spRe: pb de saisie dans un formulaire cmi111/2/2005
 sp spRe: pb de saisie dans un formulaire Oznog1/2/2005
 sp spRe: pb de saisie dans un formulaire cmi117/2/2005
 sp spRe: pb de saisie dans un formulaire cmi1114/2/2005
Aucun médias sociaux
X

Trucsweb.com Connexion

X

Trucsweb.com Mot de passe perdu

X

Trucsweb.com Conditions générales

Conditions

Responsabilité

La responsabilité des Trucsweb.com ne pourra être engagée en cas de faits indépendants de sa volonté. Les informations mises à disposition sur ce site le sont uniquement à titre purement informatif et ne sauraient constituer en aucun cas un conseil ou une recommandation de quelque nature que ce soit.

Aucun contrôle n'est exercé sur les références et ressources externes, l'utilisateur reconnaît que les Trucsweb.com n'assume aucune responsabilité relative à la mise à disposition de ces ressources, et ne peut être tenue responsable quant à leur contenu.

Droit applicable et juridiction compétente

Les règles en matière de droit, applicables aux contenus et aux transmissions de données sur et autour du site, sont déterminées par la loi canadienne. En cas de litige, n'ayant pu faire l'objet d'un accord à l'amiable, seuls les tribunaux canadien sont compétents.

X

Trucsweb.com Trucsweb

X

Trucsweb.com Glossaire

X

Trucsweb.com Trucsweb

X

Trucsweb.com Trucsweb

Conditions

Aucun message!

Merci.

X
Aucun message!
X

Trucsweb.com Créer un compte