Cgi C程序将值返回到主HTML并显示结果 [英] Cgi C program return value to main HTML and display result

查看:384
本文介绍了Cgi C程序将值返回到主HTML并显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cgi在Apache机器上编写服务器端脚本。我正在使用C进行cgi编程。我是一个菜鸟,还是从在线示例中学习(我必须说,除了基础知识之外,我没有从更多的网络资源中获得详细的学习信息!)。
我有一个简单的HTML页面,其中将用户名(输入)添加到列表中,该列表是我系统中的文件,然后更新的列表应显示在SAME PAGE中。
我无法在同一页面上打印脚本和http链接的结果,因此在下面的代码中,您只会看到按钮。请帮忙。

I am programming a server side script on an Apache machine with cgi. I am using C for the cgi programming. I am a total noob and learning from online examples(I must say except the basics I didn't come across more web sources for detailed learning!). I am having a simple HTML page where the username(input) is added to a list which is a file I have in my system and then the updated list should be displayed in the SAME PAGE. I am not able to "print" the results of both the script and http link on the same page so therefore in the code below, you will only see buttons. Please help.

这里是我所拥有的:
Html:

Here is what I have: Html:

<html>
<head><title>Home</title></head>
<body>
<h1>REGISTER</h1>
<form action= "/cgi-bin/mycgi.cgi" name ="create user" method ="get">
Enter name:<input type="text" name="user">
<br>
<input type="submit" value="add">
</form>
 <FORM action="http://localhost:8000/getusers/" method="get">
    <P>
    <input value="Display Users" type="submit">
    </P>
 </FORM>
</body>

以下是CGI代码:

#include<stdio.h>
#include<string.h>

int main(){
char *tmpStr;
char *user;
printf("Content-Type:text/html\n\n");
printf("<html><head><title></title></head><body>");
tmpStr = getenv("QUERY_STRING");
while(tmpStr && *tmpStr != '='){
tmpStr++;
}
user = tmpStr+1,
printf("Adding %s to  User Database",user);
//system("wget http://localhost:8000/newuser/");//call script to add user?
printf("</body></html>");  
return 0;//return user?
}

您能告诉我如何实现这些吗?如何在不打开新的html站点的情况下显示用户列表?同样在上面的C代码中,我必须调用链接 http:// localhost:8000 / newuser / ,该链接将返回成功或失败值。如何将其返回到父表单?
谢谢。

Could you please tell me how I can realize these? How can I display the user list without opening a new html site? Also in the above C code, I have to call the link "http://localhost:8000/newuser/" which returns a success or failure value. How can I return it to the parent form? Thanks.

推荐答案

您可以将iframe添加到html中:

You could add an iframe to your html:

<iframe id="theiframe" name="theiframe"></iframe>

然后将表单的目标设置为iframe:

And then setting the target of your form to the iframe:

<form action= "/cgi-bin/mycgi.cgi" name ="create user" method ="get" target="theiframe">

无论如何,我不清楚在单击第一个按钮时是否应显示更新的列表或第二个按钮。

Anyway, it is not clear to me if the updated list should be displayed when you click on the first or second button.

这篇关于Cgi C程序将值返回到主HTML并显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆