fc 1,c++ & mysql program.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi there,

heres a tough problem:
i have created a cgi scipt using c++ using fc1, as follows:


using namespace std;
# include <mysql/mysql.h>
# include <iostream>
# include <string>
# include <cstdio>
# include <cstdlib>

void sql_insert (const string dest [])
{
	char *qbuff;
	MYSQL mysql;
	MYSQL_RES* res;
	MYSQL_ROW row;
	mysql_init (&mysql);
	mysql_real_connect
(&mysql,NULL,"root",NULL,"TELECOMMUNICATION",0,0,0);
	qbuff = new char [1024];
	
	sprintf (qbuff,"insert into REGISTER values
('%s','%s','%s','%s','%s')",dest[0].c_str(),dest[1].c_str(),dest[2].c_st
r(),dest[3].c_str(),dest[4].c_str());

		mysql_query (&mysql,qbuff);
		cout << "No of row affected are: "<<
mysql_affected_rows(&mysql);
		mysql_close(&mysql);
}
void replaceAll(string & src, const string & findstr, const string &
replstr)
{
			int found = src.find(findstr);
			while (found != string::npos)
			{
				src.replace(found, find.length(),
replstr);
				found = src.find(findstr);
			}
}
void urldecode (string & s)
{
			replaceAll(s, "%2c", ",");
			replaceAll(s, "%0D%0A", "<BR>");
			replaceAll(s, "+", " ");
}
void split (const string & s, char * delim, string dest[])
{
			string temp = s;
			int count = 0;
			char *p;
			p = strtok(temp.begin(), delim);
			while(p != NULL)
			{
				dest[count] = p;
				count++;
				p = strtok(0, delim);
			}
			for(int temp=0;temp != count;temp++)
				dest[temp].erase(0,dest[temp].find("=")
+1);
}
int main()
{
	string s(getenv("QURY_STRING"));
	urldecode(s);
	string dest[6];
	split (s, "&", dest);
	sql_insert (dest);
	cout << "content_type:text/html" << endl << endl;
	cout << "<HTML>";
	cout << "<H1>" << "CUSTOMER DETAILS " <<"</H1>";
	cout << "<H4>";
	cout << "<BR> Name : " << dest[0] << "<BR>";
	cout << "<BR> Address : " << dest[1] << "<BR>";
	cout << "<BR> City : " << dest[2] << "<BR>";
	cout << "<BR> Phone: " << dest[3] << "<BR>";
	cout << "<BR> E-mail:" << dest[4] << "<BR>";
	cout << "<TEXTAREA NAME= 'S1' ROW='5' COLS='20'>" << dest[0]
 	     << endl << dest[1] << endl << dest[2] << endl <<dest[3]<<
endl << dest[4] << "</TEXTAREA><BR>";
	cout << "<BR>record inserted" << "<BR>";
	cout << "</h4>";
	cout << "</HTML>";
	return 0;
}

//Ok,this program inserts a new record from a html page & then inserts
it into a mysql database.
//However when I compile the program it generates the following error:

register_insert.cc: In function `void
replaceAll(std::string&, const
   std::string&, const std::string&)':
register_insert.cc:30: error: request for member `length'
in `std::find', which
   is of non-aggregate type `<unknown type>'
register_insert.cc: In function `void split(const
std::string&, char*,
   std::string*)':
register_insert.cc:45: error: cannot convert `
   __gnu_cxx::__normal_iterator<char*,
std::basic_string<char,
   std::char_traits<char>, std::allocator<char> > >' to
`char*' for argument `1
   ' to `char* strtok(char*, const char*)' 

//I have no idea whats wrong??
//strangely this works perfectly in linux 7.3


//thanxs a million
//desperate Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 6/7/2004
 



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux