Saturday, 15 June 2013

html - Problems with getenv("QUERY_STRING") in C language -



html - Problems with getenv("QUERY_STRING") in C language -

i'm new fellow member of community it's long long time on here solutions problems, today it's time me express mine. can't anymore :p ok so, have this: write html form allow me insert name, surname, username, password , email, , submit button. have write cgi c language creates page of welcome if username , password exist , display html page welcome message. otherways display sign-in page , new user stored in xml file of did dtd. problem (i think) che cgi file bad formed or have bad settings..

the form in html this:

<html> <head> <meta http-equiv="content-type" content="text/html"; charset="iso-8859-1"> <title>esegui l'accesso</title> </head> <body> <p>inserisci seguenti dati:</p> <form action="http://127.0.0.1/cgi-bin/accesso.cgi" method="get"> <label>nome:<label><br /> <input type="text" name="nome"> <br /> <label>cognome:</label><br /> <input type="text" name="cognome"> <br /> <label>username:</label><br /> <input type="text" name="username"> <br /> <label>password:</label><br /> <input type="text" name="password"> <br /> <input type="submit" name="inviodati" value="accedi"> </form> </body> </html>

now in cgi wrote:

#include <stdio.h> #include <stdlib.h> void main(){ char *data, nome[50], cognome[50]; data=getenv("query_string"); //i sould string //nome="value"&cognome="value"&username="value"&password="value" printf("content-type:'text/plain'; charset='us-ascii'\n\n"); printf("<html>\n"); printf("<head>\n"); printf("<title>benvenuto</title>\n"); printf("</head>"); printf("<body>\n"); if(data == null){ printf("<p>error! error in passing info form script.</p>"); } else{ sscanf(data, "nome=%[0-9a-za-z]&cognome=%[0-9a-za-z]",&nome,&cognome); printf("<h2>benvenuto %s %s</h2>",nome,cognome); } printf("</body>\n"); printf("</html>"); system("pause"); return(0); }

with code i'm still not trying store data, trying display welcome message , check if cgi works. server error message telling me server overloaded or there error cgi file.

i'm using xampp set html form file in htdocs folder , source c file in cgi-bin folder after renamed extension .cgi.

i hope can help me solving problem cos it's whole day i'm hitting head against keyboard :d p.s. sorry if maybe english language not :)

html c xampp cgi query-string

No comments:

Post a Comment