|
下面这段代码编译能通过,并且执行后mysql数据库里的数据也更改了,但就是在网页上没有输出,是什么地方的错?急!
#include <iostream>
#include <mysql/mysql.h>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
struct Data
{
string name, passwd, truename, city, address, phone, email;
};
class UpdateInfo
{
private:
string input, dest[7];
char *updatesql;
Data dataObj;
public:
void get()
{
input.assign(getenv("QUERY_STRING"));
}
void replaceAll(const string &findstr, const string &replstr)
{
int found = input.find(findstr);
while(found != string::npos)
{
input.replace(found, findstr.length(), replstr);
found = input.find(findstr);
}
}
void urldecode()
{
replaceAll("%2C", ",");
replaceAll("+", " ");
split();
}
void split()
{
int count = 0;
char *p;
char temp[512];
strcpy(temp,input.c_str());
p = strtok(temp, "&");
while(p != NULL)
{
dest[count]=p;
count++;
p = strtok(0, "&");
}
for(int counter = 0; counter != count; counter++)
{
dest[counter].erase(0,dest[counter].find("=") + 1);
}
dataObj.name=dest[0];
dataObj.passwd=dest[1];
dataObj.truename=dest[2];
dataObj.city=dest[3];
dataObj.address=dest[4];
dataObj.phone=dest[5];
dataObj.email=dest[6];
}
void updateData(char *updateCustomer)
{
MYSQL mysql;
MYSQL_ROW row;
char *qbuff;
qbuff=new char[512];
mysql_init(&mysql);
mysql_real_connect(&mysql,NULL,"root",NULL,"Diaz",0,0,0);
sprintf(qbuff,updateCustomer);
mysql_query(&mysql,qbuff);
if(mysql_affected_rows(&mysql)!=0)
{
cout << "个人信息修改成功!点击";
cout << "<a href=http://127.0.0.1/html/index.html>";
cout << "这里</a>返回首页";
}
else
{
cout << "用户名或密码错误!点击";
cout << "<a href=http://127.0.0.1/html/updateinfo.html>";
cout << "这里</a>返回";
}
delete qbuff;
mysql_close(&mysql);
}
void update()
{
updatesql= new char [512];
if(dest[0].length() != 0 && dest[1].length() != 0)
{
if(dest[2].length()!= 0)
{
sprintf(updatesql,"update Customer set cName = '%s' where cLoginName='%s' and cLoginPasswd='%s'",dest[2].c_str(),dest[0].c_str(),dest[1].c_str());
updateData(updatesql);
}
if(dest[3].length()!=0)
{
sprintf(updatesql,"update Customer set cCity = '%s' where cLoginName='%s' and cLoginPasswd='%s'",dest[3].c_str(),dest[0].c_str(),dest[1].c_str());
updateData(updatesql);
}
if(dest[4].length()!=0)
{
sprintf(updatesql,"update Customer set cAddress= '%s' where cLoginName='%s' and cLoginPasswd='%s'",dest[4].c_str(),dest[0].c_str(),dest[1].c_str());
updateData(updatesql);
}
if(dest[5].length()!=0)
{
sprintf(updatesql,"update Customer set cPhone = '%s' where cLoginName='%s' and cLoginPasswd='%s'",dest[5].c_str(),dest[0].c_str(),dest[1].c_str());
updateData(updatesql);
}
if(dest[6].length()!=0)
{
sprintf(updatesql,"update Customer set cEmail = '%s' where cLoginName='%s' and cLoginPasswd='%s'",dest[6].c_str(),dest[0].c_str(),dest[1].c_str());
updateData(updatesql);
}
}
else
{
cout << "请输入您的用户名和密码,谢谢!点击";
cout << "<a href=http://127.0.0.1/html/updateinfo.html>";
cout << "这里</a>返回";
}
}
};
int main()
{
cout << "content-type: text/html" << endl << endl;
cout << "<html><h1>";
cout << "hello"; //连这句都不能输出。
UpdateInfo obj;
obj.get();
obj.urldecode();
obj.split();
obj.update();
cout << "</h1></html>";
return 0;
}
//下面这个简单的就能输出
/*int main()
{
cout << "content-type: text/html" << endl << endl;
cout << "<html><h1>hello</h1></html>";
return 0;
}*/
肯定不会是中文的问题。 |
|